6 log "github.com/sirupsen/logrus"
8 "github.com/bytom/blockchain/txbuilder"
9 "github.com/bytom/crypto/ed25519/chainkd"
12 func (a *API) pseudohsmCreateKey(ctx context.Context, in struct {
13 Alias string `json:"alias"`
14 Password string `json:"password"`
16 xpub, err := a.wallet.Hsm.XCreate(in.Alias, in.Password)
18 return NewErrorResponse(err)
20 return NewSuccessResponse(xpub)
23 func (a *API) pseudohsmListKeys(ctx context.Context) Response {
24 return NewSuccessResponse(a.wallet.Hsm.ListKeys())
27 func (a *API) pseudohsmDeleteKey(ctx context.Context, x struct {
28 Password string `json:"password"`
29 XPub chainkd.XPub `json:"xpub"`
31 if err := a.wallet.Hsm.XDelete(x.XPub, x.Password); err != nil {
32 return NewErrorResponse(err)
34 return NewSuccessResponse(nil)
37 type signResp struct {
38 Tx *txbuilder.Template `json:"transaction"`
39 SignComplete bool `json:"sign_complete"`
42 func (a *API) pseudohsmSignTemplates(ctx context.Context, x struct {
43 Password string `json:"password"`
44 Txs txbuilder.Template `json:"transaction"`
46 if err := txbuilder.Sign(ctx, &x.Txs, x.Password, a.pseudohsmSignTemplate); err != nil {
47 log.WithField("build err", err).Error("fail on sign transaction.")
48 return NewErrorResponse(err)
50 log.Info("Sign Transaction complete.")
51 return NewSuccessResponse(&signResp{Tx: &x.Txs, SignComplete: txbuilder.SignProgress(&x.Txs)})
54 func (a *API) pseudohsmSignTemplate(ctx context.Context, xpub chainkd.XPub, path [][]byte, data [32]byte, password string) ([]byte, error) {
55 return a.wallet.Hsm.XSign(xpub, path, data[:], password)
58 // ResetPasswordResp is response for reset password password
59 type ResetPasswordResp struct {
60 Changed bool `json:"changed"`
63 func (a *API) pseudohsmResetPassword(ctx context.Context, ins struct {
64 XPub chainkd.XPub `json:"xpub"`
65 OldPassword string `json:"old_password"`
66 NewPassword string `json:"new_password"`
68 resp := &ResetPasswordResp{Changed: false}
69 if err := a.wallet.Hsm.ResetPassword(ins.XPub, ins.OldPassword, ins.NewPassword); err != nil {
70 return NewSuccessResponse(resp)
73 return NewSuccessResponse(resp)