diff --git a/cmd/gossamer/account.go b/cmd/gossamer/account.go index 319bd04d371..8ce542d8b16 100644 --- a/cmd/gossamer/account.go +++ b/cmd/gossamer/account.go @@ -104,7 +104,7 @@ func getKeystorePassword(ctx *cli.Context) []byte { // KeypairInserter inserts a keypair. type KeypairInserter interface { - Insert(kp crypto.Keypair) error + Insert(kp keystore.KeyPair) error } // unlockKeystore compares the length of passwords to the length of accounts, diff --git a/dot/core/interface.go b/dot/core/interface.go index 0efe12139d1..12ff117e719 100644 --- a/dot/core/interface.go +++ b/dot/core/interface.go @@ -14,6 +14,7 @@ import ( "github.com/ChainSafe/gossamer/dot/state" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/common" + "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/keystore" "github.com/ChainSafe/gossamer/lib/runtime" rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage" @@ -98,3 +99,11 @@ type CodeSubstitutedState interface { type Telemetry interface { SendMessage(msg json.Marshaler) } + +// KeyPair is a key pair to sign messages and from which +// the public key and key type can be obtained. +type KeyPair interface { + Type() crypto.KeyType + Sign(msg []byte) ([]byte, error) + Public() crypto.PublicKey +} diff --git a/dot/core/service.go b/dot/core/service.go index a0702fd0b55..343a6c99dcb 100644 --- a/dot/core/service.go +++ b/dot/core/service.go @@ -15,7 +15,6 @@ import ( "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/lib/blocktree" "github.com/ChainSafe/gossamer/lib/common" - "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/keystore" "github.com/ChainSafe/gossamer/lib/runtime" rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage" @@ -452,7 +451,7 @@ func (s *Service) maintainTransactionPool(block *types.Block, bestBlockHash comm } // InsertKey inserts keypair into the account keystore -func (s *Service) InsertKey(kp crypto.Keypair, keystoreType string) error { +func (s *Service) InsertKey(kp KeyPair, keystoreType string) error { ks, err := s.keys.GetKeystore([]byte(keystoreType)) if err != nil { return err diff --git a/dot/core/service_test.go b/dot/core/service_test.go index bc670c7197a..0219c11e51d 100644 --- a/dot/core/service_test.go +++ b/dot/core/service_test.go @@ -934,7 +934,7 @@ func TestServiceInsertKey(t *testing.T) { keyring, _ := keystore.NewSr25519Keyring() aliceKeypair := keyring.Alice().(*sr25519.Keypair) type args struct { - kp crypto.Keypair + kp KeyPair keystoreType string } tests := []struct { diff --git a/dot/rpc/interfaces.go b/dot/rpc/interfaces.go index 970578c61d1..8a0667730f5 100644 --- a/dot/rpc/interfaces.go +++ b/dot/rpc/interfaces.go @@ -6,10 +6,10 @@ package rpc import ( "encoding/json" + "github.com/ChainSafe/gossamer/dot/core" "github.com/ChainSafe/gossamer/dot/state" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/common" - "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/crypto/ed25519" "github.com/ChainSafe/gossamer/lib/genesis" "github.com/ChainSafe/gossamer/lib/grandpa" @@ -82,7 +82,7 @@ type TransactionStateAPI interface { // CoreAPI is the interface for the core methods type CoreAPI interface { - InsertKey(kp crypto.Keypair, keystoreType string) error + InsertKey(kp core.KeyPair, keystoreType string) error HasKey(pubKeyStr string, keyType string) (bool, error) GetRuntimeVersion(bhash *common.Hash) (runtime.Version, error) HandleSubmittedExtrinsic(types.Extrinsic) error diff --git a/dot/rpc/modules/api.go b/dot/rpc/modules/api.go index cd5fe3ef043..34ac27b9b21 100644 --- a/dot/rpc/modules/api.go +++ b/dot/rpc/modules/api.go @@ -4,10 +4,10 @@ package modules import ( + "github.com/ChainSafe/gossamer/dot/core" "github.com/ChainSafe/gossamer/dot/state" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/common" - "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/crypto/ed25519" "github.com/ChainSafe/gossamer/lib/genesis" "github.com/ChainSafe/gossamer/lib/grandpa" @@ -89,7 +89,7 @@ type TransactionStateAPI interface { // CoreAPI is the interface for the core methods type CoreAPI interface { - InsertKey(kp crypto.Keypair, keystoreType string) error + InsertKey(kp core.KeyPair, keystoreType string) error HasKey(pubKeyStr string, keyType string) (bool, error) GetRuntimeVersion(bhash *common.Hash) (runtime.Version, error) HandleSubmittedExtrinsic(types.Extrinsic) error diff --git a/dot/rpc/modules/api_mocks.go b/dot/rpc/modules/api_mocks.go index 74180db96bb..4385e5ee03e 100644 --- a/dot/rpc/modules/api_mocks.go +++ b/dot/rpc/modules/api_mocks.go @@ -56,7 +56,7 @@ func NewMockeryBlockAPI(t *testing.T) *modulesmocks.BlockAPI { // NewMockCoreAPI creates and return an rpc CoreAPI interface mock func NewMockCoreAPI(t *testing.T) *modulesmocks.CoreAPI { m := modulesmocks.NewCoreAPI(t) - m.On("InsertKey", mock.AnythingOfType("crypto.Keypair"), mock.AnythingOfType("string")).Return(nil).Maybe() + m.On("InsertKey", mock.AnythingOfType("core.Keypair"), mock.AnythingOfType("string")).Return(nil).Maybe() m.On("HasKey", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(false, nil).Maybe() m.On("GetRuntimeVersion", mock.AnythingOfType("*common.Hash")). Return(runtime.Version{SpecName: []byte(`mock-spec`)}, nil).Maybe() diff --git a/dot/rpc/modules/author_integration_test.go b/dot/rpc/modules/author_integration_test.go index 008bc38b579..338d404cddf 100644 --- a/dot/rpc/modules/author_integration_test.go +++ b/dot/rpc/modules/author_integration_test.go @@ -349,10 +349,14 @@ func TestAuthorModule_InsertKey_Integration(t *testing.T) { t.Run(tname, func(t *testing.T) { t.Parallel() - var expectedKp crypto.Keypair + type keyPair interface { + Public() crypto.PublicKey + } + + var expectedKp keyPair var pubkey string - if kp, ok := tt.kp.(crypto.Keypair); ok { + if kp, ok := tt.kp.(keyPair); ok { expectedKp = kp pubkey = kp.Public().Hex() } else { diff --git a/dot/rpc/modules/mocks/core_api.go b/dot/rpc/modules/mocks/core_api.go index bd42f7765e1..3e445e62696 100644 --- a/dot/rpc/modules/mocks/core_api.go +++ b/dot/rpc/modules/mocks/core_api.go @@ -3,8 +3,8 @@ package mocks import ( + core "github.com/ChainSafe/gossamer/dot/core" common "github.com/ChainSafe/gossamer/lib/common" - crypto "github.com/ChainSafe/gossamer/lib/crypto" mock "github.com/stretchr/testify/mock" @@ -153,11 +153,11 @@ func (_m *CoreAPI) HasKey(pubKeyStr string, keyType string) (bool, error) { } // InsertKey provides a mock function with given fields: kp, keystoreType -func (_m *CoreAPI) InsertKey(kp crypto.Keypair, keystoreType string) error { +func (_m *CoreAPI) InsertKey(kp core.KeyPair, keystoreType string) error { ret := _m.Called(kp, keystoreType) var r0 error - if rf, ok := ret.Get(0).(func(crypto.Keypair, string) error); ok { + if rf, ok := ret.Get(0).(func(core.KeyPair, string) error); ok { r0 = rf(kp, keystoreType) } else { r0 = ret.Error(0) diff --git a/dot/services.go b/dot/services.go index eea4bd230e0..687c74bda9d 100644 --- a/dot/services.go +++ b/dot/services.go @@ -186,7 +186,7 @@ func (nb nodeBuilder) createBABEService(cfg *Config, st *state.Service, ks KeySt type KeyStore interface { Name() keystore.Name Type() string - Keypairs() []crypto.Keypair + Keypairs() []keystore.KeyPair } func (nodeBuilder) createBABEServiceWithBuilder(cfg *Config, st *state.Service, ks KeyStore, diff --git a/lib/crypto/keypair.go b/lib/crypto/keypair.go index a32e2d02022..31b04cd7a5e 100644 --- a/lib/crypto/keypair.go +++ b/lib/crypto/keypair.go @@ -26,14 +26,6 @@ const Secp256k1Type KeyType = "secp256k1" // UnknownType is used by the GenericKeystore const UnknownType KeyType = "unknown" -// Keypair interface -type Keypair interface { - Type() KeyType - Sign(msg []byte) ([]byte, error) - Public() PublicKey - Private() PrivateKey -} - // PublicKey interface type PublicKey interface { Verify(msg, sig []byte) (bool, error) diff --git a/lib/keystore/basic_keystore.go b/lib/keystore/basic_keystore.go index e0890ed156d..fc670b6f767 100644 --- a/lib/keystore/basic_keystore.go +++ b/lib/keystore/basic_keystore.go @@ -21,7 +21,7 @@ var ( type BasicKeystore struct { name Name typ crypto.KeyType - keys map[common.Address]crypto.Keypair // map of public key encodings to keypairs + keys map[common.Address]KeyPair // map of public key encodings to keypairs lock sync.RWMutex } @@ -30,7 +30,7 @@ func NewBasicKeystore(name Name, typ crypto.KeyType) *BasicKeystore { return &BasicKeystore{ name: name, typ: typ, - keys: make(map[common.Address]crypto.Keypair), + keys: make(map[common.Address]KeyPair), } } @@ -50,7 +50,7 @@ func (ks *BasicKeystore) Size() int { } // Insert adds a keypair to the keystore -func (ks *BasicKeystore) Insert(kp crypto.Keypair) error { +func (ks *BasicKeystore) Insert(kp KeyPair) error { ks.lock.Lock() defer ks.lock.Unlock() @@ -65,7 +65,7 @@ func (ks *BasicKeystore) Insert(kp crypto.Keypair) error { } // GetKeypair returns a keypair corresponding to the given public key, or nil if it doesn't exist -func (ks *BasicKeystore) GetKeypair(pub crypto.PublicKey) crypto.Keypair { +func (ks *BasicKeystore) GetKeypair(pub crypto.PublicKey) KeyPair { for _, key := range ks.keys { if bytes.Equal(key.Public().Encode(), pub.Encode()) { return key @@ -75,7 +75,7 @@ func (ks *BasicKeystore) GetKeypair(pub crypto.PublicKey) crypto.Keypair { } // GetKeypairFromAddress returns a keypair corresponding to the given address, or nil if it doesn't exist -func (ks *BasicKeystore) GetKeypairFromAddress(pub common.Address) crypto.Keypair { +func (ks *BasicKeystore) GetKeypairFromAddress(pub common.Address) KeyPair { ks.lock.RLock() defer ks.lock.RUnlock() return ks.keys[pub] @@ -96,8 +96,7 @@ func (ks *BasicKeystore) PublicKeys() []crypto.PublicKey { } // Keypairs returns all keypairs in the keystore -func (ks *BasicKeystore) Keypairs() []crypto.Keypair { - srkeys := []crypto.Keypair{} +func (ks *BasicKeystore) Keypairs() (srkeys []KeyPair) { if ks.keys == nil { return srkeys } diff --git a/lib/keystore/generic_keystore.go b/lib/keystore/generic_keystore.go index 76ed219ea21..3f4f12e08a6 100644 --- a/lib/keystore/generic_keystore.go +++ b/lib/keystore/generic_keystore.go @@ -17,7 +17,7 @@ import ( // GenericKeystore holds keys of any type type GenericKeystore struct { name Name - keys map[common.Address]crypto.Keypair // map of public key encodings to keypairs + keys map[common.Address]KeyPair // map of public key encodings to keypairs lock sync.RWMutex } @@ -25,7 +25,7 @@ type GenericKeystore struct { func NewGenericKeystore(name Name) *GenericKeystore { return &GenericKeystore{ name: name, - keys: make(map[common.Address]crypto.Keypair), + keys: make(map[common.Address]KeyPair), } } @@ -45,7 +45,7 @@ func (ks *GenericKeystore) Size() int { } // Insert adds a keypair to the keystore -func (ks *GenericKeystore) Insert(kp crypto.Keypair) error { +func (ks *GenericKeystore) Insert(kp KeyPair) error { ks.lock.Lock() defer ks.lock.Unlock() @@ -56,7 +56,7 @@ func (ks *GenericKeystore) Insert(kp crypto.Keypair) error { } // GetKeypair returns a keypair corresponding to the given public key, or nil if it doesn't exist -func (ks *GenericKeystore) GetKeypair(pub crypto.PublicKey) crypto.Keypair { +func (ks *GenericKeystore) GetKeypair(pub crypto.PublicKey) KeyPair { for _, key := range ks.keys { if bytes.Equal(key.Public().Encode(), pub.Encode()) { return key @@ -66,7 +66,7 @@ func (ks *GenericKeystore) GetKeypair(pub crypto.PublicKey) crypto.Keypair { } // GetKeypairFromAddress returns a keypair corresponding to the given address, or nil if it doesn't exist -func (ks *GenericKeystore) GetKeypairFromAddress(pub common.Address) crypto.Keypair { +func (ks *GenericKeystore) GetKeypairFromAddress(pub common.Address) KeyPair { ks.lock.RLock() defer ks.lock.RUnlock() return ks.keys[pub] @@ -87,8 +87,7 @@ func (ks *GenericKeystore) PublicKeys() []crypto.PublicKey { } // Keypairs returns all keypairs in the keystore -func (ks *GenericKeystore) Keypairs() []crypto.Keypair { - srkeys := []crypto.Keypair{} +func (ks *GenericKeystore) Keypairs() (srkeys []KeyPair) { if ks.keys == nil { return srkeys } @@ -125,8 +124,7 @@ func (ks *GenericKeystore) Ed25519PublicKeys() []crypto.PublicKey { } // Ed25519Keypairs Keypair -func (ks *GenericKeystore) Ed25519Keypairs() []crypto.Keypair { - edkeys := []crypto.Keypair{} +func (ks *GenericKeystore) Ed25519Keypairs() (edkeys []KeyPair) { if ks.keys == nil { return edkeys } @@ -155,8 +153,7 @@ func (ks *GenericKeystore) Sr25519PublicKeys() []crypto.PublicKey { } // Sr25519Keypairs Keypair -func (ks *GenericKeystore) Sr25519Keypairs() []crypto.Keypair { - srkeys := []crypto.Keypair{} +func (ks *GenericKeystore) Sr25519Keypairs() (srkeys []KeyPair) { if ks.keys == nil { return srkeys } @@ -185,8 +182,7 @@ func (ks *GenericKeystore) Secp256k1PublicKeys() []crypto.PublicKey { } // Secp256k1Keypairs Keypair -func (ks *GenericKeystore) Secp256k1Keypairs() []crypto.Keypair { - sckeys := []crypto.Keypair{} +func (ks *GenericKeystore) Secp256k1Keypairs() (sckeys []KeyPair) { if ks.keys == nil { return sckeys } diff --git a/lib/keystore/helpers.go b/lib/keystore/helpers.go index 10c0c9a99d1..f8dd1c3aac3 100644 --- a/lib/keystore/helpers.go +++ b/lib/keystore/helpers.go @@ -21,7 +21,7 @@ import ( ) // PrivateKeyToKeypair returns a public, private keypair given a private key -func PrivateKeyToKeypair(priv crypto.PrivateKey) (kp crypto.Keypair, err error) { +func PrivateKeyToKeypair(priv crypto.PrivateKey) (kp KeyPair, err error) { if key, ok := priv.(*sr25519.PrivateKey); ok { kp, err = sr25519.NewKeypairFromPrivate(key) } else if key, ok := priv.(*ed25519.PrivateKey); ok { @@ -51,7 +51,7 @@ func DecodePrivateKey(in []byte, keytype crypto.KeyType) (priv crypto.PrivateKey } // DecodeKeyPairFromHex turns an hex-encoded private key into a keypair -func DecodeKeyPairFromHex(keystr []byte, keytype crypto.KeyType) (kp crypto.Keypair, err error) { +func DecodeKeyPairFromHex(keystr []byte, keytype crypto.KeyType) (kp KeyPair, err error) { switch keytype { case crypto.Sr25519Type: kp, err = sr25519.NewKeypairFromSeed(keystr) @@ -67,7 +67,7 @@ func DecodeKeyPairFromHex(keystr []byte, keytype crypto.KeyType) (kp crypto.Keyp // GenerateKeypair create a new keypair with the corresponding type and saves // it to basepath/keystore/[public key].key in json format encrypted using the // specified password and returns the resulting filepath of the new key -func GenerateKeypair(keytype string, kp crypto.Keypair, basepath string, password []byte) (string, error) { +func GenerateKeypair(keytype string, kp PublicPrivater, basepath string, password []byte) (string, error) { if keytype == "" { keytype = crypto.Sr25519Type } @@ -115,15 +115,15 @@ func GenerateKeypair(keytype string, kp crypto.Keypair, basepath string, passwor func LoadKeystore(key string, ks TyperInserter) (err error) { if key != "" { var kr interface { - Alice() crypto.Keypair - Bob() crypto.Keypair - Charlie() crypto.Keypair - Dave() crypto.Keypair - Eve() crypto.Keypair - Ferdie() crypto.Keypair - George() crypto.Keypair - Heather() crypto.Keypair - Ian() crypto.Keypair + Alice() KeyPair + Bob() KeyPair + Charlie() KeyPair + Dave() KeyPair + Eve() KeyPair + Ferdie() KeyPair + George() KeyPair + Heather() KeyPair + Ian() KeyPair } switch ks.Type() { @@ -204,7 +204,7 @@ func ImportKeypair(fp, dir string) (string, error) { // ImportRawPrivateKey imports a raw private key and saves it to the keystore directory func ImportRawPrivateKey(key, keytype, basepath string, password []byte) (string, error) { - var kp crypto.Keypair + var kp PublicPrivater var err error if keytype == "" { diff --git a/lib/keystore/interfaces.go b/lib/keystore/interfaces.go new file mode 100644 index 00000000000..d1bd7cc4427 --- /dev/null +++ b/lib/keystore/interfaces.go @@ -0,0 +1,36 @@ +// Copyright 2022 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + +package keystore + +import "github.com/ChainSafe/gossamer/lib/crypto" + +// KeyPair is a key pair to sign messages and from which +// the public key and key type can be obtained. +type KeyPair interface { + Sign(msg []byte) ([]byte, error) + Publicer + Typer +} + +// PublicPrivater can return the private or public key +// from the keypair. +type PublicPrivater interface { + Publicer + Privater +} + +// Publicer returns the public key of the keypair. +type Publicer interface { + Public() crypto.PublicKey +} + +// Privater returns the private key of the keypair. +type Privater interface { + Private() crypto.PrivateKey +} + +// Typer returns the key type. +type Typer interface { + Type() crypto.KeyType +} diff --git a/lib/keystore/keyring.go b/lib/keystore/keyring.go index a2788e74271..840887092aa 100644 --- a/lib/keystore/keyring.go +++ b/lib/keystore/keyring.go @@ -7,7 +7,6 @@ import ( "reflect" "github.com/ChainSafe/gossamer/lib/common" - "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/crypto/ed25519" "github.com/ChainSafe/gossamer/lib/crypto/sr25519" ) @@ -67,47 +66,47 @@ func NewSr25519Keyring() (*Sr25519Keyring, error) { } // Alice returns Alice's key -func (kr *Sr25519Keyring) Alice() crypto.Keypair { +func (kr *Sr25519Keyring) Alice() KeyPair { return kr.KeyAlice } // Bob returns Bob's key -func (kr *Sr25519Keyring) Bob() crypto.Keypair { +func (kr *Sr25519Keyring) Bob() KeyPair { return kr.KeyBob } // Charlie returns Charlie's key -func (kr *Sr25519Keyring) Charlie() crypto.Keypair { +func (kr *Sr25519Keyring) Charlie() KeyPair { return kr.KeyCharlie } // Dave returns Dave's key -func (kr *Sr25519Keyring) Dave() crypto.Keypair { +func (kr *Sr25519Keyring) Dave() KeyPair { return kr.KeyDave } // Eve returns Eve's key -func (kr *Sr25519Keyring) Eve() crypto.Keypair { +func (kr *Sr25519Keyring) Eve() KeyPair { return kr.KeyEve } // Ferdie returns Ferdie's key -func (kr *Sr25519Keyring) Ferdie() crypto.Keypair { +func (kr *Sr25519Keyring) Ferdie() KeyPair { return kr.KeyFerdie } // George returns George's key -func (kr *Sr25519Keyring) George() crypto.Keypair { +func (kr *Sr25519Keyring) George() KeyPair { return kr.KeyGeorge } // Heather returns Heather's key -func (kr *Sr25519Keyring) Heather() crypto.Keypair { +func (kr *Sr25519Keyring) Heather() KeyPair { return kr.KeyHeather } // Ian returns Ian's key -func (kr *Sr25519Keyring) Ian() crypto.Keypair { +func (kr *Sr25519Keyring) Ian() KeyPair { return kr.KeyIan } @@ -159,46 +158,46 @@ func NewEd25519Keyring() (*Ed25519Keyring, error) { } // Alice returns Alice's key -func (kr *Ed25519Keyring) Alice() crypto.Keypair { +func (kr *Ed25519Keyring) Alice() KeyPair { return kr.KeyAlice } // Bob returns Bob's key -func (kr *Ed25519Keyring) Bob() crypto.Keypair { +func (kr *Ed25519Keyring) Bob() KeyPair { return kr.KeyBob } // Charlie returns Charlie's key -func (kr *Ed25519Keyring) Charlie() crypto.Keypair { +func (kr *Ed25519Keyring) Charlie() KeyPair { return kr.KeyCharlie } // Dave returns Dave's key -func (kr *Ed25519Keyring) Dave() crypto.Keypair { +func (kr *Ed25519Keyring) Dave() KeyPair { return kr.KeyDave } // Eve returns Eve's key -func (kr *Ed25519Keyring) Eve() crypto.Keypair { +func (kr *Ed25519Keyring) Eve() KeyPair { return kr.KeyEve } // Ferdie returns Ferdie's key -func (kr *Ed25519Keyring) Ferdie() crypto.Keypair { +func (kr *Ed25519Keyring) Ferdie() KeyPair { return kr.KeyFerdie } // George returns George's key -func (kr *Ed25519Keyring) George() crypto.Keypair { +func (kr *Ed25519Keyring) George() KeyPair { return kr.KeyGeorge } // Heather returns Heather's key -func (kr *Ed25519Keyring) Heather() crypto.Keypair { +func (kr *Ed25519Keyring) Heather() KeyPair { return kr.KeyHeather } // Ian returns Ian's key -func (kr *Ed25519Keyring) Ian() crypto.Keypair { +func (kr *Ed25519Keyring) Ian() KeyPair { return kr.KeyIan } diff --git a/lib/keystore/keystore.go b/lib/keystore/keystore.go index 3ded30e1118..d9c70a904bd 100644 --- a/lib/keystore/keystore.go +++ b/lib/keystore/keystore.go @@ -34,15 +34,15 @@ type Keystore interface { Typer Inserter AddressKeypairGetter - Keypairs() []crypto.Keypair - GetKeypair(pub crypto.PublicKey) crypto.Keypair + Keypairs() []KeyPair + GetKeypair(pub crypto.PublicKey) KeyPair PublicKeys() []crypto.PublicKey Size() int } // AddressKeypairGetter gets a keypair from an address. type AddressKeypairGetter interface { - GetKeypairFromAddress(pub common.Address) crypto.Keypair + GetKeypairFromAddress(pub common.Address) KeyPair } // TyperInserter has the Type and Insert methods. @@ -51,14 +51,9 @@ type TyperInserter interface { Inserter } -// Typer returns the key type. -type Typer interface { - Type() crypto.KeyType -} - // Inserter inserts a keypair. type Inserter interface { - Insert(kp crypto.Keypair) error + Insert(kp KeyPair) error } // GlobalKeystore defines the various keystores used by the node diff --git a/lib/runtime/wasmer/imports.go b/lib/runtime/wasmer/imports.go index 5c88fa5a4bf..82b4f7d038a 100644 --- a/lib/runtime/wasmer/imports.go +++ b/lib/runtime/wasmer/imports.go @@ -234,7 +234,7 @@ func ext_crypto_ed25519_generate_version_1(context unsafe.Pointer, keyTypeID C.i return 0 } - var kp crypto.Keypair + var kp KeyPair if seed != nil { kp, err = ed25519.NewKeypairFromMnenomic(string(*seed), "") @@ -559,7 +559,7 @@ func ext_crypto_sr25519_generate_version_1(context unsafe.Pointer, keyTypeID C.i return 0 } - var kp crypto.Keypair + var kp KeyPair if seed != nil { kp, err = sr25519.NewKeypairFromMnenomic(string(*seed), "") } else { diff --git a/lib/runtime/wasmer/interfaces.go b/lib/runtime/wasmer/interfaces.go index 93094c699df..9981f67d450 100644 --- a/lib/runtime/wasmer/interfaces.go +++ b/lib/runtime/wasmer/interfaces.go @@ -5,6 +5,7 @@ package wasmer import ( "github.com/ChainSafe/gossamer/lib/common" + "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/transaction" "github.com/ChainSafe/gossamer/lib/trie" ) @@ -57,3 +58,11 @@ type BasicNetwork interface { type TransactionState interface { AddToPool(vt *transaction.ValidTransaction) common.Hash } + +// KeyPair is a key pair to sign messages and from which +// the public key can be obtained. +type KeyPair interface { + Sign(msg []byte) ([]byte, error) + Public() crypto.PublicKey + Type() crypto.KeyType +}