Skip to content

Commit c8a0fb3

Browse files
authored
Default initial wallet account name + require names (keybase#13855)
* require wallet account names * fix test
1 parent cde017b commit c8a0fb3

14 files changed

Lines changed: 83 additions & 39 deletions

File tree

‎go/client/cmd_wallet_import.go‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (c *cmdWalletImport) ParseArgv(ctx *cli.Context) (err error) {
4949
}
5050

5151
func (c *cmdWalletImport) Run() (err error) {
52+
ctx := context.TODO()
5253
secKey, accountID, err := c.promptSecretKey()
5354
if err != nil {
5455
return err
@@ -59,20 +60,26 @@ func (c *cmdWalletImport) Run() (err error) {
5960
return err
6061
}
6162

62-
own, err := cli.OwnAccountLocal(context.TODO(), accountID)
63+
own, err := cli.OwnAccountLocal(ctx, accountID)
6364
if err != nil {
6465
return err
6566
}
6667
if own {
6768
return fmt.Errorf("account has already been imported: %v", accountID)
6869
}
70+
c.G().UI.GetTerminalUI().Printf(fmt.Sprintf("Ready to import account: %v\n", accountID))
71+
name, err := c.promptAccountName(ctx)
72+
if err != nil {
73+
return err
74+
}
6975
err = c.confirm(accountID)
7076
if err != nil {
7177
return err
7278
}
73-
err = cli.ImportSecretKeyLocal(context.TODO(), stellar1.ImportSecretKeyLocalArg{
79+
err = cli.ImportSecretKeyLocal(ctx, stellar1.ImportSecretKeyLocalArg{
7480
SecretKey: secKey,
7581
MakePrimary: c.makePrimary,
82+
Name: name,
7683
})
7784
if err != nil {
7885
return err
@@ -102,12 +109,13 @@ func (c *cmdWalletImport) promptSecretKey() (stellar1.SecretKey, stellar1.Accoun
102109
return secKey, accountID, err
103110
}
104111

112+
func (c *cmdWalletImport) promptAccountName(ctx context.Context) (string, error) {
113+
return c.G().UI.GetTerminalUI().Prompt(PromptDescriptorImportStellarAccountName, "Enter a private name for this account: ")
114+
}
115+
105116
func (c *cmdWalletImport) confirm(accountID stellar1.AccountID) error {
106-
promptText := fmt.Sprintf(`
107-
Ready to import account: %v
108-
The stellar secret key will be encrypted, uploaded, and made available on all of your devices.
109-
Ready to import?`, accountID)
110-
doIt, err := c.G().UI.GetTerminalUI().PromptYesNo(PromptDescriptorConfirmStellarImport, promptText, libkb.PromptDefaultYes)
117+
c.G().UI.GetTerminalUI().Printf("The stellar secret key will be encrypted, uploaded, and made available on all of your devices.\n")
118+
doIt, err := c.G().UI.GetTerminalUI().PromptYesNo(PromptDescriptorConfirmStellarImport, "Ready to import?", libkb.PromptDefaultYes)
111119
if err != nil {
112120
return err
113121
}

‎go/client/prompts.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const (
6565
PromptDescriptorConfirmStellarImport
6666
PromptDescriptorChatSetConvMinWriterRole
6767
PromptDescriptorChangeLockdownMode
68+
PromptDescriptorImportStellarAccountName
6869
)
6970

7071
const (

‎go/protocol/stellar1/local.go‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go/stellar/bundle/main.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stellar/go/keypair"
99
)
1010

11-
func NewInitialBundle() (res stellar1.Bundle, err error) {
11+
func NewInitialBundle(accountName string) (res stellar1.Bundle, err error) {
1212
accountID, masterKey, err := randomStellarKeypair()
1313
if err != nil {
1414
return res, err
@@ -22,7 +22,7 @@ func NewInitialBundle() (res stellar1.Bundle, err error) {
2222
Mode: stellar1.AccountMode_USER,
2323
IsPrimary: true,
2424
Signers: []stellar1.SecretKey{masterKey},
25-
Name: "",
25+
Name: accountName,
2626
}},
2727
}, nil
2828
}
@@ -45,6 +45,9 @@ func AddAccount(bundle *stellar1.Bundle, secretKey stellar1.SecretKey, name stri
4545
if err != nil {
4646
return err
4747
}
48+
if name == "" {
49+
return fmt.Errorf("Name required for new account")
50+
}
4851
if makePrimary {
4952
for i := range bundle.Accounts {
5053
bundle.Accounts[i].IsPrimary = false

‎go/stellar/remote/remote.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func addWalletServerArg(serverArg libkb.JSONPayload, bundleEncB64 string, bundle
208208
section["encrypted"] = bundleEncB64
209209
section["visible"] = bundleVisB64
210210
section["version"] = formatVersion
211+
section["miniversion"] = 2
211212
serverArg["stellar"] = section
212213
}
213214

‎go/stellar/stellar.go‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ const AccountNameMaxRunes = 24
3131
// Safe (but wasteful) to call even if the user has a bundle already.
3232
func CreateWallet(ctx context.Context, g *libkb.GlobalContext) (created bool, err error) {
3333
defer g.CTraceTimed(ctx, "Stellar.CreateWallet", func() error { return err })()
34-
clearBundle, err := bundle.NewInitialBundle()
34+
loggedInUsername := g.ActiveDevice.Username(libkb.NewMetaContext(ctx, g))
35+
if !loggedInUsername.IsValid() {
36+
return false, fmt.Errorf("could not get logged-in username")
37+
}
38+
clearBundle, err := bundle.NewInitialBundle(fmt.Sprintf("%v's account", loggedInUsername))
3539
if err != nil {
36-
return created, err
40+
return false, err
3741
}
3842
meUV, err := g.GetMeUV(ctx)
3943
if err != nil {
@@ -1014,10 +1018,13 @@ func reverse(s string) string {
10141018

10151019
// ChangeAccountName changes the name of an account.
10161020
// Make sure to keep this in sync with ValidateAccountNameLocal.
1017-
// An empty name is always acceptable.
1021+
// An empty name is not allowed.
10181022
// Renaming an account to an already used name is blocked.
10191023
// Maximum length of AccountNameMaxRunes runes.
10201024
func ChangeAccountName(m libkb.MetaContext, accountID stellar1.AccountID, newName string) (err error) {
1025+
if newName == "" {
1026+
return fmt.Errorf("name required")
1027+
}
10211028
runes := utf8.RuneCountInString(newName)
10221029
if runes > AccountNameMaxRunes {
10231030
return fmt.Errorf("account name can be %v characters at the longest but was %v", AccountNameMaxRunes, runes)

‎go/stellar/stellarsvc/frontend.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func (s *Server) ValidateAccountNameLocal(ctx context.Context, arg stellar1.Vali
500500
}
501501
// Make sure to keep this validation in sync with ChangeAccountName.
502502
if arg.Name == "" {
503-
return nil
503+
return fmt.Errorf("name required")
504504
}
505505
runes := utf8.RuneCountInString(arg.Name)
506506
if runes > stellar.AccountNameMaxRunes {

‎go/stellar/stellarsvc/frontend_test.go‎

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func TestGetWalletAccountsLocal(t *testing.T) {
2727

2828
accountID := tcs[0].Backend.AddAccount()
2929

30-
argImport := stellar1.ImportSecretKeyLocalArg{
30+
err = tcs[0].Srv.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
3131
SecretKey: tcs[0].Backend.SecretKey(accountID),
3232
MakePrimary: true,
33-
}
34-
err = tcs[0].Srv.ImportSecretKeyLocal(context.Background(), argImport)
33+
Name: "qq",
34+
})
3535
require.NoError(t, err)
3636

3737
tcs[0].Backend.ImportAccountsForUser(tcs[0])
@@ -42,26 +42,28 @@ func TestGetWalletAccountsLocal(t *testing.T) {
4242
require.Len(t, accts, 2)
4343
require.Equal(t, accountID, accts[0].AccountID, accountID)
4444
require.True(t, accts[0].IsDefault)
45-
require.Equal(t, "", accts[0].Name) // TODO: once we can set the name on an account, check this
45+
require.Equal(t, "qq", accts[0].Name)
4646
require.Equal(t, "10,000.00 XLM", accts[0].BalanceDescription)
4747
require.NotEmpty(t, accts[0].Seqno)
4848

4949
require.False(t, accts[1].IsDefault)
50-
require.Equal(t, "", accts[1].Name)
50+
require.Equal(t, firstAccountName(t, tcs[0]), accts[1].Name)
5151
require.Equal(t, "0 XLM", accts[1].BalanceDescription)
5252
require.NotEmpty(t, accts[1].Seqno)
5353

5454
// test the singular version as well
5555
argDetails := stellar1.GetWalletAccountLocalArg{AccountID: accountID}
5656
details, err := tcs[0].Srv.GetWalletAccountLocal(context.Background(), argDetails)
5757
require.NoError(t, err)
58+
require.Equal(t, "qq", accts[0].Name)
5859
require.True(t, details.IsDefault)
5960
require.Equal(t, "10,000.00 XLM", details.BalanceDescription)
6061
require.NotEmpty(t, details.Seqno)
6162

6263
argDetails.AccountID = accts[1].AccountID
6364
details, err = tcs[0].Srv.GetWalletAccountLocal(context.Background(), argDetails)
6465
require.NoError(t, err)
66+
require.Equal(t, firstAccountName(t, tcs[0]), accts[1].Name)
6567
require.False(t, details.IsDefault)
6668
require.Equal(t, "0 XLM", details.BalanceDescription)
6769
require.NotEmpty(t, details.Seqno)
@@ -76,11 +78,11 @@ func TestGetAccountAssetsLocalWithBalance(t *testing.T) {
7678

7779
accountID := tcs[0].Backend.AddAccount()
7880

79-
argImport := stellar1.ImportSecretKeyLocalArg{
81+
err = tcs[0].Srv.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
8082
SecretKey: tcs[0].Backend.SecretKey(accountID),
8183
MakePrimary: true,
82-
}
83-
err = tcs[0].Srv.ImportSecretKeyLocal(context.Background(), argImport)
84+
Name: "qq",
85+
})
8486
require.NoError(t, err)
8587

8688
tcs[0].Backend.ImportAccountsForUser(tcs[0])
@@ -209,7 +211,7 @@ func TestChangeWalletName(t *testing.T) {
209211
accs, err := tcs[0].Srv.WalletGetAccountsCLILocal(context.Background())
210212
require.NoError(t, err)
211213
require.Len(t, accs, 1)
212-
require.Equal(t, accs[0].Name, "")
214+
require.Equal(t, accs[0].Name, firstAccountName(t, tcs[0]))
213215

214216
chk := func(name string, expected string) {
215217
err = tcs[0].Srv.ValidateAccountNameLocal(context.Background(), stellar1.ValidateAccountNameLocalArg{Name: name})
@@ -221,7 +223,7 @@ func TestChangeWalletName(t *testing.T) {
221223
}
222224
}
223225

224-
chk("", "")
226+
chk("", "name required")
225227
chk("office lunch money", "")
226228
chk("savings", "")
227229
err = tcs[0].Srv.ChangeWalletAccountNameLocal(context.Background(), stellar1.ChangeWalletAccountNameLocalArg{
@@ -294,11 +296,11 @@ func TestSetAccountAsDefault(t *testing.T) {
294296
}
295297

296298
for _, v := range additionalAccs {
297-
arg := stellar1.ImportSecretKeyLocalArg{
299+
err = tcs[0].Srv.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
298300
SecretKey: tcs[0].Backend.SecretKey(v),
299301
MakePrimary: false,
300-
}
301-
err = tcs[0].Srv.ImportSecretKeyLocal(context.Background(), arg)
302+
Name: "qq",
303+
})
302304
require.NoError(t, err)
303305
}
304306

@@ -360,7 +362,7 @@ func testCreateOrLinkNewAccount(t *testing.T, create bool) {
360362

361363
require.Len(t, accts, 2)
362364
require.True(t, accts[0].IsDefault)
363-
require.Equal(t, "", accts[0].Name)
365+
require.Equal(t, firstAccountName(t, tcs[0]), accts[0].Name)
364366
require.Equal(t, "0 XLM", accts[0].BalanceDescription)
365367
require.False(t, accts[1].IsDefault)
366368
require.Equal(t, accID, accts[1].AccountID)
@@ -405,6 +407,7 @@ func TestDeleteWallet(t *testing.T) {
405407
err = tcs[0].Srv.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
406408
SecretKey: tcs[0].Backend.SecretKey(accID2),
407409
MakePrimary: true,
410+
Name: "qq",
408411
})
409412
require.NoError(t, err)
410413

@@ -604,6 +607,7 @@ func TestGetPaymentsLocal(t *testing.T) {
604607
err = srvSender.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
605608
SecretKey: rm.SecretKey(accountIDSender),
606609
MakePrimary: true,
610+
Name: "qq",
607611
})
608612
require.NoError(t, err)
609613

@@ -616,12 +620,14 @@ func TestGetPaymentsLocal(t *testing.T) {
616620
err = srvRecip.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
617621
SecretKey: rm.SecretKey(accountIDRecip),
618622
MakePrimary: true,
623+
Name: "uu",
619624
})
620625
require.NoError(t, err)
621626

622627
err = srvRecip.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
623628
SecretKey: rm.SecretKey(accountIDRecip2),
624629
MakePrimary: false,
630+
Name: "vv",
625631
})
626632
require.NoError(t, err)
627633

@@ -705,7 +711,7 @@ func TestGetPaymentsLocal(t *testing.T) {
705711
require.Equal(t, accountIDRecip, *p.ToAccountID)
706712
var toAccountName string
707713
if !sender {
708-
toAccountName = accountIDRecip.String()
714+
toAccountName = "uu"
709715
}
710716
require.Equal(t, toAccountName, p.ToAccountName, "ToAccountName")
711717
require.Equal(t, tcs[1].Fu.Username, p.ToUsername)
@@ -807,7 +813,7 @@ func TestGetPaymentsLocal(t *testing.T) {
807813
require.Equal(t, accountIDRecip, *p.ToAccountID)
808814
var toAccountName string
809815
if !sender {
810-
toAccountName = accountIDRecip.String()
816+
toAccountName = "uu"
811817
}
812818
require.Equal(t, toAccountName, p.ToAccountName)
813819
require.Equal(t, tcs[1].Fu.Username, p.ToUsername)
@@ -897,7 +903,7 @@ func TestGetPaymentsLocal(t *testing.T) {
897903
require.Equal(t, "", p.FromAccountName)
898904
require.Equal(t, stellar1.ParticipantType_STELLAR, p.ToType)
899905
require.Equal(t, accountIDRecip2, *p.ToAccountID)
900-
require.Equal(t, accountIDRecip2.String(), p.ToAccountName)
906+
require.Equal(t, "vv", p.ToAccountName)
901907
require.Equal(t, "", p.ToUsername)
902908
require.Equal(t, "", p.ToAssertion)
903909
require.NotEmpty(t, p.NoteErr) // can't send encrypted note to stellar address
@@ -914,6 +920,7 @@ func TestSendToSelf(t *testing.T) {
914920
err := tcs[0].Srv.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
915921
SecretKey: rm.SecretKey(accountID1),
916922
MakePrimary: true,
923+
Name: "qq",
917924
})
918925
require.NoError(t, err)
919926

@@ -925,6 +932,7 @@ func TestSendToSelf(t *testing.T) {
925932

926933
err = tcs[0].Srv.ImportSecretKeyLocal(context.Background(), stellar1.ImportSecretKeyLocalArg{
927934
SecretKey: rm.SecretKey(accountID2),
935+
Name: "uu",
928936
})
929937
require.NoError(t, err)
930938

@@ -1713,3 +1721,9 @@ func (c *chatListener) ChatPaymentInfo(uid keybase1.UID, convID chat1.Conversati
17131721
func (c *chatListener) ChatRequestInfo(uid keybase1.UID, convID chat1.ConversationID, msgID chat1.MessageID, info chat1.UIRequestInfo) {
17141722
c.requestInfos <- chat1.ChatRequestInfoArg{Uid: uid, ConvID: convID, MsgID: msgID, Info: info}
17151723
}
1724+
1725+
func firstAccountName(t testing.TB, tc *TestContext) string {
1726+
loggedInUsername := tc.G.ActiveDevice.Username(libkb.NewMetaContextForTest(tc.TestContext))
1727+
require.True(t, loggedInUsername.IsValid())
1728+
return fmt.Sprintf("%v's account", loggedInUsername)
1729+
}

‎go/stellar/stellarsvc/service.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (s *Server) ImportSecretKeyLocal(ctx context.Context, arg stellar1.ImportSe
112112
return err
113113
}
114114

115-
return stellar.ImportSecretKey(ctx, s.G(), arg.SecretKey, arg.MakePrimary, "")
115+
return stellar.ImportSecretKey(ctx, s.G(), arg.SecretKey, arg.MakePrimary, arg.Name)
116116
}
117117

118118
func (s *Server) ExportSecretKeyLocal(ctx context.Context, accountID stellar1.AccountID) (res stellar1.SecretKey, err error) {

0 commit comments

Comments
 (0)