@@ -187,6 +187,21 @@ The setpw command stores a password for a given address (keyfile).
187187 Description : `
188188The delpw command removes a password for a given address (keyfile).
189189` }
190+ newAccountCommand = cli.Command {
191+ Action : utils .MigrateFlags (newAccount ),
192+ Name : "newaccount" ,
193+ Usage : "Create a new account" ,
194+ ArgsUsage : "" ,
195+ Flags : []cli.Flag {
196+ logLevelFlag ,
197+ keystoreFlag ,
198+ utils .LightKDFFlag ,
199+ },
200+ Description : `
201+ The newaccount command creates a new keystore-backed account. It is a convenience-method
202+ which can be used in lieu of an external UI.` ,
203+ }
204+
190205 gendocCommand = cli.Command {
191206 Action : GenDoc ,
192207 Name : "gendoc" ,
@@ -222,7 +237,12 @@ func init() {
222237 advancedMode ,
223238 }
224239 app .Action = signer
225- app .Commands = []cli.Command {initCommand , attestCommand , setCredentialCommand , delCredentialCommand , gendocCommand }
240+ app .Commands = []cli.Command {initCommand ,
241+ attestCommand ,
242+ setCredentialCommand ,
243+ delCredentialCommand ,
244+ newAccountCommand ,
245+ gendocCommand }
226246 cli .CommandHelpTemplate = utils .OriginCommandHelpTemplate
227247}
228248
@@ -382,6 +402,31 @@ func removeCredential(ctx *cli.Context) error {
382402 return nil
383403}
384404
405+ func newAccount (c * cli.Context ) error {
406+ if err := initialize (c ); err != nil {
407+ return err
408+ }
409+ // The newaccount is meant for users using the CLI, since 'real' external
410+ // UIs can use the UI-api instead. So we'll just use the native CLI UI here.
411+ var (
412+ ui = core .NewCommandlineUI ()
413+ pwStorage storage.Storage = & storage.NoStorage {}
414+ ksLoc = c .GlobalString (keystoreFlag .Name )
415+ lightKdf = c .GlobalBool (utils .LightKDFFlag .Name )
416+ )
417+ log .Info ("Starting clef" , "keystore" , ksLoc , "light-kdf" , lightKdf )
418+ am := core .StartClefAccountManager (ksLoc , true , lightKdf , "" )
419+ // This gives is us access to the external API
420+ apiImpl := core .NewSignerAPI (am , 0 , true , ui , nil , false , pwStorage )
421+ // This gives us access to the internal API
422+ internalApi := core .NewUIServerAPI (apiImpl )
423+ addr , err := internalApi .New (context .Background ())
424+ if err == nil {
425+ fmt .Printf ("Generated account %v\n " , addr .String ())
426+ }
427+ return err
428+ }
429+
385430func initialize (c * cli.Context ) error {
386431 // Set up the logger to print everything
387432 logOutput := os .Stdout
@@ -457,7 +502,6 @@ func signer(c *cli.Context) error {
457502 api core.ExternalAPI
458503 pwStorage storage.Storage = & storage.NoStorage {}
459504 )
460-
461505 configDir := c .GlobalString (configdirFlag .Name )
462506 if stretchedKey , err := readMasterKey (c , ui ); err != nil {
463507 log .Warn ("Failed to open master, rules disabled" , "err" , err )
0 commit comments