Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enter the new keyring interface #5904

Merged
merged 164 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 161 commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
705a417
New keyring interface
Mar 26, 2020
13a973d
temp commit
jgimeno Mar 26, 2020
d5c2018
temp commit
jgimeno Mar 26, 2020
1baf2b6
add test for list
jgimeno Mar 26, 2020
ece95ef
test adding new key
jgimeno Mar 26, 2020
cdada42
add test for list
jgimeno Mar 26, 2020
760b167
implement and test Key
jgimeno Mar 26, 2020
de39a80
create and test GetByAddress
jgimeno Mar 26, 2020
85c4fd5
add delete function
jgimeno Mar 27, 2020
36548a7
add delete by address function
jgimeno Mar 27, 2020
57f7d5a
add new pub key and test
jgimeno Mar 27, 2020
2d22fbd
create function for writing multisign
jgimeno Mar 27, 2020
a9aab77
use addrKeyByString
jgimeno Mar 27, 2020
63fbdf3
implement and test multisig
jgimeno Mar 27, 2020
7255a32
add test for unsupported signing algo
jgimeno Mar 27, 2020
f3e0624
refactor algorithm
jgimeno Mar 27, 2020
0edc2d8
supported algorithm changed
jgimeno Mar 27, 2020
758af07
update al keyring
jgimeno Mar 27, 2020
a990c74
update options
jgimeno Mar 27, 2020
d999ad1
add supported algorithm test and SAveLedgerKey
jgimeno Mar 27, 2020
04b03a7
fix imports
jgimeno Mar 27, 2020
1c736f1
add signature into keyring
jgimeno Mar 30, 2020
9ede030
add method to sign by address
jgimeno Mar 30, 2020
869b35a
implement import export
jgimeno Mar 30, 2020
67c4942
implement the alt keyring
jgimeno Mar 30, 2020
482f55f
finish implementing altKeyring
jgimeno Mar 30, 2020
6434960
refactor thekey
jgimeno Mar 30, 2020
d86b467
fix the tests
jgimeno Mar 30, 2020
a0304e5
fixt ci linter errors
jgimeno Mar 30, 2020
717dae3
fix other lint
jgimeno Mar 30, 2020
f58970d
New keyring interface
Mar 26, 2020
1ff6830
temp commit
jgimeno Mar 26, 2020
21121cb
temp commit
jgimeno Mar 26, 2020
f3e7d8a
add test for list
jgimeno Mar 26, 2020
518ace9
test adding new key
jgimeno Mar 26, 2020
195de90
add test for list
jgimeno Mar 26, 2020
cdc534c
implement and test Key
jgimeno Mar 26, 2020
516ec8b
create and test GetByAddress
jgimeno Mar 26, 2020
1d795bf
add delete function
jgimeno Mar 27, 2020
2e3a8ac
add delete by address function
jgimeno Mar 27, 2020
b94cfff
add new pub key and test
jgimeno Mar 27, 2020
de0976e
create function for writing multisign
jgimeno Mar 27, 2020
46a5436
use addrKeyByString
jgimeno Mar 27, 2020
b475b6c
implement and test multisig
jgimeno Mar 27, 2020
5f961e3
add test for unsupported signing algo
jgimeno Mar 27, 2020
b704745
refactor algorithm
jgimeno Mar 27, 2020
0f4e1ed
supported algorithm changed
jgimeno Mar 27, 2020
a9fdd20
update al keyring
jgimeno Mar 27, 2020
d5ca45e
update options
jgimeno Mar 27, 2020
5c66495
add supported algorithm test and SAveLedgerKey
jgimeno Mar 27, 2020
cc2b794
fix imports
jgimeno Mar 27, 2020
a39fd3d
add signature into keyring
jgimeno Mar 30, 2020
59f9b4d
add method to sign by address
jgimeno Mar 30, 2020
a7c397e
implement import export
jgimeno Mar 30, 2020
dabff2d
implement the alt keyring
jgimeno Mar 30, 2020
639b1ca
finish implementing altKeyring
jgimeno Mar 30, 2020
8ad06f9
refactor thekey
jgimeno Mar 30, 2020
39ab64a
fix the tests
jgimeno Mar 30, 2020
ce541b1
fixt ci linter errors
jgimeno Mar 30, 2020
e98322a
fix other lint
jgimeno Mar 30, 2020
c0201b1
Merge branch 'jonathan/keyring-refactor-interface' of github.com:cosm…
jgimeno Mar 31, 2020
d48b298
Merge branch 'master' into alessio/new-keyring-interface
Mar 31, 2020
04ebcb3
Import interface from jonathan's branch
Mar 31, 2020
7a79f58
Merge branch 'alessio/new-keyring-interface' into jonathan/keyring-re…
Mar 31, 2020
ec5a657
clean up the diff
Mar 31, 2020
f62f1d2
fix tests after merge
jgimeno Mar 31, 2020
fbf08c2
add interface for signing algo
jgimeno Mar 31, 2020
54f27e1
add option to provide signingalgos and testse
jgimeno Mar 31, 2020
dbeea70
change Name to String in AltSigningAlgo
jgimeno Mar 31, 2020
0f73f74
Revert "change Name to String in AltSigningAlgo"
jgimeno Mar 31, 2020
b06b3ec
Update crypto/keyring/altkeyring.go
jgimeno Apr 1, 2020
f4e9e83
Merge branch 'master' into alessio/new-keyring-interface
Apr 1, 2020
fd74489
Merge pull request #5879 from cosmos/jonathan/keyring-refactor-interface
Apr 1, 2020
5bb0cbd
Rename old SigningAlgo
Apr 1, 2020
02b70cb
Move the new interface into keyring.go
Apr 1, 2020
4474f77
Rename NewAltKeyring() -> New()
Apr 1, 2020
303a334
More renaming
Apr 1, 2020
2f525d2
add constructor
jgimeno Apr 2, 2020
37056bd
update context
jgimeno Apr 2, 2020
ad0284d
update factory tx
jgimeno Apr 2, 2020
773342a
update show
jgimeno Apr 2, 2020
0b55faf
update server init
jgimeno Apr 2, 2020
8bcc106
update tx builder
jgimeno Apr 2, 2020
51e81ee
Switch NewInMemory over new implementation
Apr 2, 2020
b68b0fd
Simplify tests
Apr 2, 2020
1abec01
Don't use infoKey with the new keyring
Apr 2, 2020
6d8031f
Fix server tests
Apr 2, 2020
9b90d3f
Merge branch 'master' into alessio/new-keyring-interface
Apr 2, 2020
d8e4640
Revert "Don't use infoKey with the new keyring"
Apr 2, 2020
c53a452
Fix tests
Apr 2, 2020
519939e
fix armor test
jgimeno Apr 2, 2020
92acbff
migrate some tests
jgimeno Apr 2, 2020
d03a7e3
migrate more tests
jgimeno Apr 2, 2020
93d16c9
migrate TestSignVerifyKeyRing
jgimeno Apr 2, 2020
fc3596c
migrate tests
jgimeno Apr 2, 2020
0b1633f
migrate TestExportImportPubKeyKeyRing function
jgimeno Apr 2, 2020
d0a59fc
migrate some tests
jgimeno Apr 2, 2020
e254e62
New interface Migrator
Apr 2, 2020
572d3f6
Merge branch 'alessio/new-keyring-interface' of github.com:cosmos/cos…
Apr 2, 2020
4ba7e39
solve tests
jgimeno Apr 2, 2020
b90e8f2
Rename
Apr 2, 2020
6ca433e
Merge branch 'alessio/new-keyring-interface' of github.com:cosmos/cos…
Apr 2, 2020
87ef1cb
migrate more tests
jgimeno Apr 2, 2020
36cc921
migrate tests
jgimeno Apr 2, 2020
88489da
Add tests
Apr 2, 2020
5128749
Merge branch 'master' into alessio/new-keyring-interface
Apr 2, 2020
6432e55
migrate more tests
jgimeno Apr 2, 2020
29214ef
migrate more tests
jgimeno Apr 2, 2020
40b32b6
remove export object
jgimeno Apr 2, 2020
2fbd136
migrate more tests
jgimeno Apr 2, 2020
095fcb7
migrate unit tests
jgimeno Apr 2, 2020
1c37647
end migrate tests
jgimeno Apr 2, 2020
97f6c8e
Update client tests
Apr 2, 2020
b211603
Substitue deprecate types with new ones
Apr 2, 2020
c974a9f
Remove baseKeybase
Apr 2, 2020
412ba96
Make golangci-lint happy
Apr 2, 2020
367ffd3
Merge branch 'master' into alessio/new-keyring-interface
Apr 2, 2020
11934f7
Rename, cleanup
Apr 2, 2020
cd85d7c
Cleanup
Apr 2, 2020
2af9073
Tidy up
Apr 2, 2020
dcb05ae
Tidy up, more tests
Apr 2, 2020
fd7ca14
temporarily fix singleton
Apr 2, 2020
1a1717b
remove unused members
Apr 2, 2020
b37a2f7
Try remove config singleton
Apr 2, 2020
6a2a1f5
Fix race condition, remove config from keyring
Apr 2, 2020
0794cc9
Merge branch 'master' into alessio/new-keyring-interface
Apr 3, 2020
7ef86c8
fix bug when importing from same seed but different keys made that ke…
jgimeno Apr 3, 2020
321a574
improve tests
Apr 3, 2020
abf382c
change options struct to make it public
jgimeno Apr 3, 2020
78508f1
move algo
jgimeno Apr 3, 2020
df54d24
refactor naming
jgimeno Apr 3, 2020
c044b6f
add types
jgimeno Apr 3, 2020
82d91a5
renama package
jgimeno Apr 3, 2020
5e49fba
make format
jgimeno Apr 3, 2020
3fd18c1
refactor some naming
jgimeno Apr 3, 2020
a81c3f5
add test
Apr 4, 2020
0a4422d
Proposed interface
Apr 4, 2020
f33a26d
Fix linter warning
Apr 4, 2020
4068b60
Rename, tests
Apr 4, 2020
8392cd5
Rename
Apr 4, 2020
7c7d284
Merge branch 'master' into alessio/new-keyring-interface
Apr 4, 2020
35ab52c
Tidy up crypto/hd tests
Apr 5, 2020
e0c825d
Create a doc.go
Apr 5, 2020
fe68ac0
Merge branch 'master' into alessio/new-keyring-interface
Apr 6, 2020
128d58d
add better existance checking
jgimeno Apr 6, 2020
5b91eda
refactor and fix check
jgimeno Apr 6, 2020
fdc522a
bits of refactoring
Apr 6, 2020
4cea6bf
Add few more doc strings
Apr 6, 2020
2e5e287
add checking to overwrite
jgimeno Apr 6, 2020
acb5e7f
fix bugs
Apr 6, 2020
8939284
Merge branch 'master' into alessio/new-keyring-interface
Apr 6, 2020
c16d93e
client/input: remove unused GetCheckPassword
Apr 6, 2020
fc81ef9
client/input: remove redundant PrintPrefixed function
Apr 6, 2020
cbfbc3e
client/input: GetConfirmation takes io.Writer to communicate with users.
Apr 6, 2020
e40b978
Simplify, don't include app name in keyring directories
Apr 6, 2020
2a674f7
tidy up, few more tests
Apr 6, 2020
67eb038
Split tests that require ledger support
Apr 6, 2020
70ca9a7
Instantiate in-memory if --gen-only is passed
Apr 7, 2020
4b8d3a1
Fallback to in memory backend
Apr 7, 2020
e72eb95
Update CHANGELOG
Apr 7, 2020
ef8eed5
Merge branch 'master' into alessio/new-keyring-interface
Apr 7, 2020
640cbec
Sort changelog, tidy up
Apr 7, 2020
2d0f3c3
Fix CHANGELOG formatting
Apr 7, 2020
c7e7534
Merge branch 'master' into alessio/new-keyring-interface
Apr 8, 2020
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ to now accept a `codec.JSONMarshaler` for modular serialization of genesis state
- `NewKeyring()` now accepts a new backend: `MemoryBackend`.
- `New()` has been renamed to`NewLegacy()`, which now returns a `LegacyKeybase` type that only allows migration of keys from the legacy keybase to a new keyring.
* (client/keys) [\#5889](https://github.com/cosmos/cosmos-sdk/pull/5889) Rename `NewKeyBaseFromDir()` -> `NewLegacyKeyBaseFromDir()`.
* (crypto/keyring) [\#5904](https://github.com/cosmos/cosmos-sdk/pull/5904) `Keybase` -> `Keyring` interfaces migration. `LegacyKeybase` interface is added in order
alessio marked this conversation as resolved.
Show resolved Hide resolved
to guarantee limited backward compatibility with the old Keybase interface for the sole purpose of migrating keys across the new keyring backends. Plus, the package
and the new keyring no longer depends on the sdk.Config singleton.
* (crypto/keys) [\#5904](https://github.com/cosmos/cosmos-sdk/pull/5904) `crypto/keys/hd` moved to `crypto/hd`.
* (client/input) [\#5904](https://github.com/cosmos/cosmos-sdk/pull/5904) Removal of unnecessary `GetCheckPassword`, `PrintPrefixed` functions.

### Features

Expand Down
43 changes: 31 additions & 12 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type CLIContext struct {
Client rpcclient.Client
ChainID string
Marshaler codec.Marshaler
Keybase keyring.Keybase
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
Input io.Reader
Keyring keyring.Keyring
Output io.Writer
OutputFormat string
Height int64
Expand Down Expand Up @@ -58,8 +58,19 @@ func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext {
var nodeURI string
var rpc rpcclient.Client

homedir := viper.GetString(flags.FlagHome)
genOnly := viper.GetBool(flags.FlagGenerateOnly)
fromAddress, fromName, err := GetFromFields(input, from, genOnly)
backend := viper.GetString(flags.FlagKeyringBackend)
if len(backend) == 0 {
backend = keyring.BackendMemory
}

keyring, err := newKeyringFromFlags(backend, homedir, input, genOnly)
if err != nil {
panic(fmt.Errorf("couldn't acquire keyring: %v", err))
}

fromAddress, fromName, err := GetFromFields(keyring, from, genOnly)
if err != nil {
fmt.Printf("failed to get from fields: %v\n", err)
os.Exit(1)
Expand All @@ -84,9 +95,10 @@ func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext {
Output: os.Stdout,
NodeURI: nodeURI,
From: viper.GetString(flags.FlagFrom),
Keyring: keyring,
OutputFormat: viper.GetString(cli.OutputFlag),
Height: viper.GetInt64(flags.FlagHeight),
HomeDir: viper.GetString(flags.FlagHome),
HomeDir: homedir,
TrustNode: viper.GetBool(flags.FlagTrustNode),
UseLedger: viper.GetBool(flags.FlagUseLedger),
BroadcastMode: viper.GetString(flags.FlagBroadcastMode),
Expand Down Expand Up @@ -129,6 +141,12 @@ func NewCLIContextWithInput(input io.Reader) CLIContext {
return NewCLIContextWithInputAndFrom(input, viper.GetString(flags.FlagFrom))
}

// WithKeyring returns a copy of the context with an updated keyring.
func (ctx CLIContext) WithKeyring(k keyring.Keyring) CLIContext {
ctx.Keyring = k
return ctx
}

// WithInput returns a copy of the context with an updated input.
func (ctx CLIContext) WithInput(r io.Reader) CLIContext {
ctx.Input = r
Expand Down Expand Up @@ -307,7 +325,7 @@ func (ctx CLIContext) PrintOutput(toPrint interface{}) error {
// GetFromFields returns a from account address and Keybase name given either
// an address or key name. If genOnly is true, only a valid Bech32 cosmos
// address is returned.
func GetFromFields(input io.Reader, from string, genOnly bool) (sdk.AccAddress, string, error) {
func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddress, string, error) {
if from == "" {
return nil, "", nil
}
Expand All @@ -321,24 +339,25 @@ func GetFromFields(input io.Reader, from string, genOnly bool) (sdk.AccAddress,
return addr, "", nil
}

keybase, err := keyring.NewKeyring(sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input)
if err != nil {
return nil, "", err
}

var info keyring.Info
if addr, err := sdk.AccAddressFromBech32(from); err == nil {
info, err = keybase.GetByAddress(addr)
info, err = kr.KeyByAddress(addr)
if err != nil {
return nil, "", err
}
} else {
info, err = keybase.Get(from)
info, err = kr.Key(from)
if err != nil {
return nil, "", err
}
}

return info.GetAddress(), info.GetName(), nil
}

func newKeyringFromFlags(backend, homedir string, input io.Reader, genOnly bool) (keyring.Keyring, error) {
if genOnly {
return keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, homedir, input)
}
return keyring.New(sdk.KeyringServiceName(), backend, homedir, input)
}
27 changes: 23 additions & 4 deletions client/context/context_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package context
package context_test

import (
"os"
"testing"

"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/spf13/viper"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
)

func TestCLIContext_WithOffline(t *testing.T) {
viper.Set(flags.FlagOffline, true)
viper.Set(flags.FlagNode, "tcp://localhost:26657")

ctx := NewCLIContext()
ctx := context.NewCLIContext()
require.True(t, ctx.Offline)
require.Nil(t, ctx.Client)

Expand All @@ -24,7 +27,7 @@ func TestCLIContext_WithOffline(t *testing.T) {
viper.Set(flags.FlagOffline, false)
viper.Set(flags.FlagNode, "tcp://localhost:26657")

ctx = NewCLIContext()
ctx = context.NewCLIContext()
require.False(t, ctx.Offline)
require.NotNil(t, ctx.Client)
}
Expand Down Expand Up @@ -59,10 +62,26 @@ func TestCLIContext_WithGenOnly(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
ctx := NewCLIContextWithFrom(tt.from)
ctx := context.NewCLIContextWithFrom(tt.from)

require.Equal(t, tt.expectedFromAddr, ctx.FromAddress)
require.Equal(t, tt.expectedFromName, ctx.FromName)
})
}
}

func TestCLIContext_WithKeyring(t *testing.T) {
viper.Set(flags.FlagGenerateOnly, true)
ctx := context.NewCLIContextWithFrom("cosmos1q7380u26f7ntke3facjmynajs4umlr329vr4ja")
require.NotNil(t, ctx.Keyring)
kr := ctx.Keyring
ctx = ctx.WithKeyring(nil)
require.Nil(t, ctx.Keyring)
ctx = ctx.WithKeyring(kr)
require.Equal(t, kr, ctx.Keyring)
}

func TestMain(m *testing.M) {
viper.Set(flags.FlagKeyringBackend, keyring.BackendMemory)
os.Exit(m.Run())
}
39 changes: 4 additions & 35 deletions client/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package input

import (
"bufio"
"errors"
"fmt"
"io"
"os"
"strings"

Expand Down Expand Up @@ -36,40 +36,15 @@ func GetPassword(prompt string, buf *bufio.Reader) (pass string, err error) {
return pass, nil
}

// GetCheckPassword will prompt for a password twice to verify they
// match (for creating a new password).
// It enforces the password length. Only parses password once if
// input is piped in.
func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, error) {
// simple read on no-tty
if !inputIsTty() {
return GetPassword(prompt, buf)
}

// TODO: own function???
pass, err := GetPassword(prompt, buf)
if err != nil {
return "", err
}
pass2, err := GetPassword(prompt2, buf)
if err != nil {
return "", err
}
if pass != pass2 {
return "", errors.New("passphrases don't match")
}
return pass, nil
}

// GetConfirmation will request user give the confirmation from stdin.
// "y", "Y", "yes", "YES", and "Yes" all count as confirmations.
// If the input is not recognized, it returns false and a nil error.
func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
func GetConfirmation(prompt string, r *bufio.Reader, w io.Writer) (bool, error) {
if inputIsTty() {
fmt.Printf("%s [y/N]: ", prompt)
}

response, err := readLineFromBuf(buf)
response, err := readLineFromBuf(r)
if err != nil {
return false, err
}
Expand All @@ -90,7 +65,7 @@ func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
// GetString simply returns the trimmed string output of a given reader.
func GetString(prompt string, buf *bufio.Reader) (string, error) {
if inputIsTty() && prompt != "" {
PrintPrefixed(prompt)
fmt.Fprintf(os.Stderr, "> %s\n", prompt)
}

out, err := readLineFromBuf(buf)
Expand All @@ -117,9 +92,3 @@ func readLineFromBuf(buf *bufio.Reader) (string, error) {
}
return strings.TrimSpace(pass), nil
}

// PrintPrefixed prints a string with > prefixed for use in prompts.
func PrintPrefixed(msg string) {
msg = fmt.Sprintf("> %s\n", msg)
fmt.Fprint(os.Stderr, msg)
}
48 changes: 25 additions & 23 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -27,6 +28,7 @@ const (
flagInteractive = "interactive"
flagRecover = "recover"
flagNoBackup = "no-backup"
flagCoinType = "coin-type"
flagAccount = "account"
flagIndex = "index"
flagMultisig = "multisig"
Expand Down Expand Up @@ -73,19 +75,20 @@ the flag --nosort is set.
cmd.Flags().Bool(flagNoBackup, false, "Don't print out seed phrase (if others are watching the terminal)")
cmd.Flags().Bool(flags.FlagDryRun, false, "Perform action, but don't add key to local keystore")
cmd.Flags().String(flagHDPath, "", "Manual HD Path derivation (overrides BIP44 config)")
cmd.Flags().Uint32(flagCoinType, sdk.CoinType, "coin type number for HD derivation")
cmd.Flags().Uint32(flagAccount, 0, "Account number for HD derivation")
cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation")
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
cmd.Flags().String(flagKeyAlgo, string(keyring.Secp256k1), "Key signing algorithm to generate keys for")
cmd.Flags().String(flagKeyAlgo, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")
return cmd
}

func getKeybase(transient bool, buf io.Reader) (keyring.Keybase, error) {
func getKeybase(transient bool, buf io.Reader) (keyring.Keyring, error) {
if transient {
return keyring.NewKeyring(sdk.KeyringServiceName(), keyring.BackendMemory, viper.GetString(flags.FlagHome), buf)
return keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, viper.GetString(flags.FlagHome), buf)
}

return keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
return keyring.New(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
}

func runAddCmd(cmd *cobra.Command, args []string) error {
Expand All @@ -107,33 +110,35 @@ input
output
- armor encrypted private key (saved to file)
*/
func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keybase, inBuf *bufio.Reader) error {
func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *bufio.Reader) error {
var err error

name := args[0]

interactive := viper.GetBool(flagInteractive)
showMnemonic := !viper.GetBool(flagNoBackup)

algo := keyring.SigningAlgo(viper.GetString(flagKeyAlgo))
if algo == keyring.SigningAlgo("") {
algo = keyring.Secp256k1
}
if !keyring.IsSupportedAlgorithm(kb.SupportedAlgos(), algo) {
return keyring.ErrUnsupportedSigningAlgo
algo, err := keyring.NewSigningAlgoFromString(viper.GetString(flagKeyAlgo))
if err != nil {
algo = hd.Secp256k1
}

if !viper.GetBool(flags.FlagDryRun) {
_, err = kb.Get(name)
_, err = kb.Key(name)
if err == nil {
// account exists, ask for user confirmation
response, err2 := input.GetConfirmation(fmt.Sprintf("override the existing name %s", name), inBuf)
response, err2 := input.GetConfirmation(fmt.Sprintf("override the existing name %s", name), inBuf, cmd.ErrOrStderr())
if err2 != nil {
return err2
}
if !response {
return errors.New("aborted")
}

err2 = kb.Delete(name)
if err2 != nil {
return err2
}
}

multisigKeys := viper.GetStringSlice(flagMultisig)
Expand All @@ -146,7 +151,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keybase, inBuf *buf
}

for _, keyname := range multisigKeys {
k, err := kb.Get(keyname)
k, err := kb.Key(keyname)
if err != nil {
return err
}
Expand All @@ -161,7 +166,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keybase, inBuf *buf
}

pk := multisig.NewPubKeyMultisigThreshold(multisigThreshold, pks)
if _, err := kb.CreateMulti(name, pk); err != nil {
if _, err := kb.SaveMultisig(name, pk); err != nil {
return err
}

Expand All @@ -175,21 +180,22 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keybase, inBuf *buf
if err != nil {
return err
}
_, err = kb.CreateOffline(name, pk, algo)
_, err = kb.SavePubKey(name, pk, algo.Name())
if err != nil {
return err
}
return nil
}

coinType := uint32(viper.GetInt(flagCoinType))
account := uint32(viper.GetInt(flagAccount))
index := uint32(viper.GetInt(flagIndex))

useBIP44 := !viper.IsSet(flagHDPath)
var hdPath string

if useBIP44 {
hdPath = keyring.CreateHDPath(account, index).String()
hdPath = hd.CreateHDPath(coinType, account, index).String()
} else {
hdPath = viper.GetString(flagHDPath)
}
Expand All @@ -201,12 +207,8 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keybase, inBuf *buf
return errors.New("cannot set custom bip32 path with ledger")
}

if !keyring.IsSupportedAlgorithm(kb.SupportedAlgosLedger(), algo) {
return keyring.ErrUnsupportedSigningAlgo
}

bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
info, err := kb.CreateLedger(name, keyring.Secp256k1, bech32PrefixAccAddr, account, index)
info, err := kb.SaveLedgerKey(name, hd.Secp256k1, bech32PrefixAccAddr, coinType, account, index)
if err != nil {
return err
}
Expand Down Expand Up @@ -269,7 +271,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keybase, inBuf *buf
}
}

info, err := kb.CreateAccount(name, mnemonic, bip39Passphrase, DefaultKeyPass, hdPath, algo)
info, err := kb.NewAccount(name, mnemonic, bip39Passphrase, hdPath, algo)
if err != nil {
return err
}
Expand Down
Loading