-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5879 from cosmos/jonathan/keyring-refactor-interface
Starting creating refactored keyring [WIP]
- Loading branch information
Showing
6 changed files
with
1,044 additions
and
67 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,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 | ||
} |
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,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 | ||
} |
Oops, something went wrong.