Skip to content

Commit

Permalink
Merge pull request #5879 from cosmos/jonathan/keyring-refactor-interface
Browse files Browse the repository at this point in the history
Starting creating refactored keyring [WIP]
  • Loading branch information
Alessio Treglia authored Apr 1, 2020
2 parents f4e9e83 + b06b3ec commit fd74489
Show file tree
Hide file tree
Showing 6 changed files with 1,044 additions and 67 deletions.
44 changes: 44 additions & 0 deletions crypto/keyring/alt_signing_algorithms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package keyring

import "github.com/tendermint/tendermint/crypto"

type AltSigningAlgo interface {
Name() SigningAlgo
DeriveKey() AltDeriveKeyFunc
PrivKeyGen() AltPrivKeyGenFunc
}

type AltDeriveKeyFunc func(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
type AltPrivKeyGenFunc func(bz []byte) crypto.PrivKey

type secp256k1Algo struct {
}

func (s secp256k1Algo) Name() SigningAlgo {
return Secp256k1
}

func (s secp256k1Algo) DeriveKey() AltDeriveKeyFunc {
return SecpDeriveKey
}

func (s secp256k1Algo) PrivKeyGen() AltPrivKeyGenFunc {
return SecpPrivKeyGen
}

var (
// Secp256k1 uses the Bitcoin secp256k1 ECDSA parameters.
AltSecp256k1 = secp256k1Algo{}
)

type AltSigningAlgoList []AltSigningAlgo

func (l AltSigningAlgoList) Contains(algo AltSigningAlgo) bool {
for _, cAlgo := range l {
if cAlgo.Name() == algo.Name() {
return true
}
}

return false
}
31 changes: 31 additions & 0 deletions crypto/keyring/alt_signing_algorithms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package keyring

import (
"testing"

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

func TestAltSigningAlgoList_Contains(t *testing.T) {
list := AltSigningAlgoList{
AltSecp256k1,
}

assert.True(t, list.Contains(AltSecp256k1))
assert.False(t, list.Contains(notSupportedAlgo{}))
}

type notSupportedAlgo struct {
}

func (n notSupportedAlgo) Name() SigningAlgo {
return "notSupported"
}

func (n notSupportedAlgo) DeriveKey() AltDeriveKeyFunc {
return SecpDeriveKey
}

func (n notSupportedAlgo) PrivKeyGen() AltPrivKeyGenFunc {
return SecpPrivKeyGen
}
Loading

0 comments on commit fd74489

Please sign in to comment.