m.Handle("/list-keys", jsonHandler(a.pseudohsmListKeys))
m.Handle("/delete-key", jsonHandler(a.pseudohsmDeleteKey))
m.Handle("/reset-key-password", jsonHandler(a.pseudohsmResetPassword))
+ m.Handle("/check-key-password", jsonHandler(a.pseudohsmCheckPassword))
m.Handle("/sign-message", jsonHandler(a.signMessage))
m.Handle("/build-transaction", jsonHandler(a.build))
return a.wallet.Hsm.XSign(xpub, path, data[:], password)
}
-// ResetPasswordResp is response for reset password password
+// ResetPasswordResp is response for reset key password
type ResetPasswordResp struct {
Changed bool `json:"changed"`
}
resp.Changed = true
return NewSuccessResponse(resp)
}
+
+// CheckPasswordResp is response for check key password
+type CheckPasswordResp struct {
+ CheckResult bool `json:"check_result"`
+}
+
+func (a *API) pseudohsmCheckPassword(ctx context.Context, ins struct {
+ XPub chainkd.XPub `json:"xpub"`
+ Password string `json:"password"`
+}) Response {
+ resp := &CheckPasswordResp{CheckResult: false}
+ if _, err := a.wallet.Hsm.LoadChainKDKey(ins.XPub, ins.Password); err != nil {
+ return NewSuccessResponse(resp)
+ }
+ resp.CheckResult = true
+ return NewSuccessResponse(resp)
+}
BytomcliCmd.AddCommand(deleteKeyCmd)
BytomcliCmd.AddCommand(listKeysCmd)
BytomcliCmd.AddCommand(resetKeyPwdCmd)
+ BytomcliCmd.AddCommand(checkKeyPwdCmd)
BytomcliCmd.AddCommand(signMsgCmd)
BytomcliCmd.AddCommand(verifyMsgCmd)
deleteKeyCmd.Name(),
listKeysCmd.Name(),
resetKeyPwdCmd.Name(),
+ checkKeyPwdCmd.Name(),
signMsgCmd.Name(),
buildTransactionCmd.Name(),
},
}
+var checkKeyPwdCmd = &cobra.Command{
+ Use: "check-key-password <xpub> <password>",
+ Short: "check key password",
+ Args: cobra.ExactArgs(2),
+ Run: func(cmd *cobra.Command, args []string) {
+ xpub := new(chainkd.XPub)
+ if err := xpub.UnmarshalText([]byte(args[0])); err != nil {
+ jww.ERROR.Println("check-key-password args not valid:", err)
+ os.Exit(util.ErrLocalExe)
+ }
+
+ ins := struct {
+ XPub chainkd.XPub `json:"xpub"`
+ Password string `json:"password"`
+ }{XPub: *xpub, Password: args[1]}
+
+ data, exitCode := util.ClientCall("/check-key-password", &ins)
+ if exitCode != util.Success {
+ os.Exit(exitCode)
+ }
+
+ printJSON(data)
+ },
+}
+
var signMsgCmd = &cobra.Command{
Use: "sign-message <address> <message> <password>",
Short: "sign message to generate signature",