log "github.com/sirupsen/logrus"
- "github.com/vapor/blockchain/txbuilder"
- "github.com/vapor/common"
- "github.com/vapor/consensus"
- "github.com/vapor/crypto"
- "github.com/vapor/crypto/ed25519/chainkd"
+ "github.com/bytom/vapor/blockchain/txbuilder"
+ "github.com/bytom/vapor/crypto/ed25519/chainkd"
)
-type createKeyResp struct {
+type CreateKeyReq struct {
+ Alias string `json:"alias"`
+ Password string `json:"password"`
+ Mnemonic string `json:"mnemonic"`
+ Language string `json:"language"`
+}
+
+type CreateKeyResp struct {
Alias string `json:"alias"`
XPub chainkd.XPub `json:"xpub"`
File string `json:"file"`
Mnemonic string `json:"mnemonic,omitempty"`
}
-func (a *API) pseudohsmCreateKey(ctx context.Context, in struct {
- Alias string `json:"alias"`
- Password string `json:"password"`
- Mnemonic string `json:"mnemonic"`
- Language string `json:"language"`
-}) Response {
+func (a *API) pseudohsmCreateKey(ctx context.Context, in CreateKeyReq) Response {
if in.Language == "" {
in.Language = "en"
}
if err != nil {
return NewErrorResponse(err)
}
- return NewSuccessResponse(&createKeyResp{Alias: xpub.Alias, XPub: xpub.XPub, File: xpub.File})
+ return NewSuccessResponse(&CreateKeyResp{Alias: xpub.Alias, XPub: xpub.XPub, File: xpub.File})
}
xpub, mnemonic, err := a.wallet.Hsm.XCreate(in.Alias, in.Password, in.Language)
if err != nil {
return NewErrorResponse(err)
}
- return NewSuccessResponse(&createKeyResp{Alias: xpub.Alias, XPub: xpub.XPub, File: xpub.File, Mnemonic: *mnemonic})
+ return NewSuccessResponse(&CreateKeyResp{Alias: xpub.Alias, XPub: xpub.XPub, File: xpub.File, Mnemonic: *mnemonic})
}
func (a *API) pseudohsmUpdateKeyAlias(ctx context.Context, in struct {
Password string `json:"password"`
Txs txbuilder.Template `json:"transaction"`
}) Response {
- if err := txbuilder.Sign(ctx, &x.Txs, x.Password, a.PseudohsmSignTemplate); err != nil {
+ if err := txbuilder.Sign(ctx, &x.Txs, x.Password, a.pseudohsmSignTemplate); err != nil {
log.WithField("build err", err).Error("fail on sign transaction.")
return NewErrorResponse(err)
}
}) Response {
signComplete := true
for _, tx := range x.Txs {
- if err := txbuilder.Sign(ctx, tx, x.Password, a.PseudohsmSignTemplate); err != nil {
+ if err := txbuilder.Sign(ctx, tx, x.Password, a.pseudohsmSignTemplate); err != nil {
log.WithField("build err", err).Error("fail on sign transaction.")
return NewErrorResponse(err)
}
return NewSuccessResponse(&signTemplatesResp{Tx: x.Txs, SignComplete: signComplete})
}
-func (a *API) PseudohsmSignTemplate(ctx context.Context, xpub chainkd.XPub, path [][]byte, data [32]byte, password string) ([]byte, error) {
+func (a *API) pseudohsmSignTemplate(ctx context.Context, xpub chainkd.XPub, path [][]byte, data [32]byte, password string) ([]byte, error) {
return a.wallet.Hsm.XSign(xpub, path, data[:], password)
}
resp.CheckResult = true
return NewSuccessResponse(resp)
}
-
-type keyPair struct {
- Xpub chainkd.XPub `json:"xpub"`
- Xprv chainkd.XPrv `json:"xprv"`
- Address string `json:"address,omitempty"`
-}
-
-func (a *API) createXKeys(ctx context.Context) Response {
- xprv, xpub, err := chainkd.NewXKeys(nil)
- if err != nil {
- return NewErrorResponse(err)
- }
-
- pubHash := crypto.Ripemd160(xpub.PublicKey())
-
- address, err := common.NewAddressWitnessPubKeyHash(pubHash, &consensus.ActiveNetParams)
- if err != nil {
- return NewErrorResponse(err)
- }
-
- return NewSuccessResponse(&keyPair{Xprv: xprv, Xpub: xpub, Address: address.EncodeAddress()})
-}