OSDN Git Service

modify reset-key-password api (#459)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Thu, 22 Mar 2018 07:04:37 +0000 (15:04 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 22 Mar 2018 07:04:37 +0000 (15:04 +0800)
* git# This is a combination of 18 commits.
fix json name for submit transaction

remove useless code in blockchain/reactor.go (#441)

add interface get-transaction (#439)

* standard transaction reserve utxo filter out contract utxo

* add interface get-transaction
motify response json name

* update dashboard

Block json (#442)

* init version of get-block api

* edit for small details

* fix for golint

init push for add newBlockCh for p2p (#443)

init push for validate-address API (#444)

init push for list address (#445)

fix transaction API response json format and bytomcli API (#446)

* standard transaction reserve utxo filter out contract utxo

* add interface get-transaction
motify response json name

* modify json name for api

* fix transaction API response json format

* bytomcli add get-block

* retired xprv

modify get-block-count API (#447)

* standard transaction reserve utxo filter out contract utxo

* add interface get-transaction
motify response json name

* modify json name for api

* fix transaction API response json format

* bytomcli add get-block

* retired xprv

* modify get-block-count

remove accounts and assets from BlockchainReactor (#448)

* remove accounts field in BlockchainReactor

* remove assets field in BlockchainReactor

put hsm from BlockchainReactor to Wallet (#451)

put token management from BlockchainReactor to Wallet (#452)

init push for submit-tx (#450)

modify get-transaction block_time types (#449)

* standard transaction reserve utxo filter out contract utxo

* add interface get-transaction
motify response json name

* modify json name for api

* fix transaction API response json format

* bytomcli add get-block

* retired xprv

* modify get-block-count

* modify block_time types
fix golint suggest

bytomcli add validate-address and list-addresses

edit the create-address api (#453)

* edit the create-address api

* update dashboard

add GetAccountBalances to wallet (#454)

* add GetAccountBalances to wallet

* fix import order

 bytomcli add validate-address and list-addresses  (#455)

* fix json name for submit transaction

* bytomcli add validate-address and list-addresses

* add reset-key-password

blockchain/hsm.go
blockchain/pseudohsm/pseudohsm.go
blockchain/rpc_reactor.go
cmd/bytomcli/commands/bytomcli.go
cmd/bytomcli/commands/key.go

index 0c36e3d..9536a02 100644 (file)
@@ -66,10 +66,13 @@ func (bcr *BlockchainReactor) pseudohsmSignTemplate(ctx context.Context, xpub ch
        return bcr.wallet.Hsm.XSign(xpub, path, data[:], password)
 }
 
-func (bcr *BlockchainReactor) pseudohsmResetPassword(ctx context.Context, x struct {
-       OldPassword string
-       NewPassword string
-       XPub        chainkd.XPub `json:"xpubs"`
-}) error {
-       return bcr.wallet.Hsm.ResetPassword(x.XPub, x.OldPassword, x.NewPassword)
+func (bcr *BlockchainReactor) pseudohsmResetPassword(ctx context.Context, ins struct {
+       XPub        chainkd.XPub `json:"xpub"`
+       OldPassword string       `json:"old_password"`
+       NewPassword string       `json:"new_password"`
+}) Response {
+       if err := bcr.wallet.Hsm.ResetPassword(ins.XPub, ins.OldPassword, ins.NewPassword); err != nil {
+               return NewErrorResponse(err)
+       }
+       return NewSuccessResponse(nil)
 }
index a08db82..3511558 100644 (file)
@@ -156,19 +156,21 @@ func (h *HSM) loadDecryptedKey(xpub chainkd.XPub, auth string) (XPub, *XKey, err
        return xpb, xkey, err
 }
 
-// ResetPassword the passphrase of an existing xpub
-func (h *HSM) ResetPassword(xpub chainkd.XPub, auth, newAuth string) error {
-       xpb, xkey, err := h.loadDecryptedKey(xpub, auth)
+// ResetPassword reset passphrase for an existing xpub
+func (h *HSM) ResetPassword(xpub chainkd.XPub, oldAuth, newAuth string) error {
+       xpb, xkey, err := h.loadDecryptedKey(xpub, oldAuth)
        if err != nil {
                return err
        }
        return h.keyStore.StoreKey(xpb.File, xkey, newAuth)
 }
 
+// HasAlias check whether the key alias exists
 func (h *HSM) HasAlias(alias string) bool {
        return h.cache.hasAlias(alias)
 }
 
+// HasKey check whether the private key exists
 func (h *HSM) HasKey(xprv chainkd.XPrv) bool {
        return h.cache.hasKey(xprv.XPub())
 }
index 8fc8e64..91fa861 100644 (file)
@@ -70,11 +70,11 @@ func (bcr *BlockchainReactor) BuildHandler() {
                m.Handle("/create-key", jsonHandler(bcr.pseudohsmCreateKey))
                m.Handle("/list-keys", jsonHandler(bcr.pseudohsmListKeys))
                m.Handle("/delete-key", jsonHandler(bcr.pseudohsmDeleteKey))
+               m.Handle("/reset-key-password", jsonHandler(bcr.pseudohsmResetPassword))
 
                m.Handle("/get-transaction", jsonHandler(bcr.getTransaction))
                m.Handle("/list-transactions", jsonHandler(bcr.listTransactions))
                m.Handle("/list-balances", jsonHandler(bcr.listBalances))
-               m.Handle("/reset-password", jsonHandler(bcr.pseudohsmResetPassword))
        } else {
                log.Warn("Please enable wallet")
        }
index 4d71042..e58850a 100644 (file)
@@ -111,6 +111,7 @@ func AddCommands() {
        BytomcliCmd.AddCommand(createKeyCmd)
        BytomcliCmd.AddCommand(deleteKeyCmd)
        BytomcliCmd.AddCommand(listKeysCmd)
+       BytomcliCmd.AddCommand(resetKeyPwdCmd)
        BytomcliCmd.AddCommand(exportPrivateCmd)
        BytomcliCmd.AddCommand(importPrivateCmd)
        BytomcliCmd.AddCommand(importKeyProgressCmd)
index 792d39c..b2c0d64 100644 (file)
@@ -70,6 +70,30 @@ var listKeysCmd = &cobra.Command{
        },
 }
 
+var resetKeyPwdCmd = &cobra.Command{
+       Use:   "reset-key-password <xpub> <old-password> <new-password>",
+       Short: "Delete a key",
+       Args:  cobra.ExactArgs(3),
+       Run: func(cmd *cobra.Command, args []string) {
+               xpub := new(chainkd.XPub)
+               if err := xpub.UnmarshalText([]byte(args[0])); err != nil {
+                       jww.ERROR.Println("reset-key-password args not vaild:", err)
+                       os.Exit(util.ErrLocalExe)
+               }
+
+               ins := struct {
+                       XPub        chainkd.XPub `json:"xpub"`
+                       OldPassword string       `json:"old_password"`
+                       NewPassword string       `json:"new_password"`
+               }{XPub: *xpub, OldPassword: args[1], NewPassword: args[2]}
+
+               if _, exitCode := util.ClientCall("/reset-key-password", &ins); exitCode != util.Success {
+                       os.Exit(exitCode)
+               }
+               jww.FEEDBACK.Println("Successfully reset key password")
+       },
+}
+
 var exportPrivateCmd = &cobra.Command{
        Use:   "export-private-key <xpub> <password>",
        Short: "Export the private key",