X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=api%2Fhsm.go;h=bdda0e6c841317268852da24d8e2af69ca6e215f;hb=55af282737c50eb50467788d499d872eb9567563;hp=96b968e5f430ce75c82e57607988bacda87a2dc3;hpb=cc968002ceac2dfd7665c2ac2b4c32ab6017b525;p=bytom%2Fvapor.git diff --git a/api/hsm.go b/api/hsm.go index 96b968e5..bdda0e6c 100644 --- a/api/hsm.go +++ b/api/hsm.go @@ -5,26 +5,25 @@ import ( 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" } @@ -33,13 +32,13 @@ func (a *API) pseudohsmCreateKey(ctx context.Context, in struct { 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 { @@ -75,7 +74,7 @@ func (a *API) signTemplate(ctx context.Context, x 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) } @@ -94,7 +93,7 @@ func (a *API) signTemplates(ctx context.Context, x struct { }) 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) } @@ -105,7 +104,7 @@ func (a *API) signTemplates(ctx context.Context, x struct { 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) } @@ -143,25 +142,3 @@ func (a *API) pseudohsmCheckPassword(ctx context.Context, ins struct { 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()}) -}