Commit b818ad31 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

fix private key

parent 82e68f7e
......@@ -13,12 +13,13 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)
func (d *Dao) Login(privateKey *ecdsa.PrivateKey, userId string, inviter string) (txHash common.Hash, err error) {
func (d *Dao) Login(byteKey []byte, userId string, inviter string) (txHash common.Hash, err error) {
instance, err := aon_user.NewAonUser(common.HexToAddress(d.c.Chain.UserContract), d.ethClient)
if err != nil {
return common.Hash{}, err
}
privateKey := crypto.ToECDSAUnsafe(byteKey)
auth, err := bind.NewKeyedTransactorWithChainID(privateKey, d.chainId)
if err != nil {
return common.Hash{}, err
......@@ -32,11 +33,12 @@ func (d *Dao) Login(privateKey *ecdsa.PrivateKey, userId string, inviter string)
return tx.Hash(), nil
}
func (d *Dao) CheckApprove(privateKey *ecdsa.PrivateKey) (txHash common.Hash, err error) {
func (d *Dao) CheckApprove(byteKey []byte) (txHash common.Hash, err error) {
instance, err := erc20.NewErc20(common.HexToAddress(d.c.Chain.AppPointContract), d.ethClient)
if err != nil {
return
}
privateKey := crypto.ToECDSAUnsafe(byteKey)
user := crypto.PubkeyToAddress(privateKey.PublicKey)
allowance, err := instance.Allowance(&bind.CallOpts{}, user, common.HexToAddress(d.c.Chain.ExecutorContract))
if err != nil {
......
......@@ -3,11 +3,11 @@ package server
import (
. "contract_backend/constant"
"contract_backend/util"
"crypto/ecdsa"
"fmt"
"io"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/gin-gonic/gin"
......@@ -33,7 +33,7 @@ func userChange(c *gin.Context) {
}
var userId string
var key *ecdsa.PrivateKey
var key *btcec.PrivateKey
operation := gjson.Get(string(rawJson), "operation").String()
switch operation {
......@@ -120,7 +120,8 @@ func userChange(c *gin.Context) {
time.Sleep(time.Second)
}
txHash, err := d.Login(key, userId, "")
// 在alpine nocgo上使用ecdsa.PrivateKey会报错 msg="call ca login error" error="private key curve is not secp256k1"
txHash, err := d.Login(key.Serialize(), userId, "")
if err != nil {
log.WithError(err).Error("call ca login error")
c.JSON(200, withError(InternalError))
......@@ -133,7 +134,7 @@ func userChange(c *gin.Context) {
}).Info("user login")
go func() {
txHash, err = d.CheckApprove(key)
txHash, err = d.CheckApprove(key.Serialize())
if err != nil {
log.WithError(err).Error("call ca check approve error")
return
......
......@@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil/hdkeychain"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
......@@ -34,7 +35,7 @@ func GetAddressByUserId(xpub, userId string) (output common.Address, err error)
return crypto.PubkeyToAddress(*pubkey), nil
}
func GetPrivateKeyByUserId(xpriv, userId string) (key *ecdsa.PrivateKey, err error) {
func GetPrivateKeyByUserId(xpriv, userId string) (key *btcec.PrivateKey, err error) {
uid, err := uuid.Parse(userId)
if err != nil {
return nil, err
......@@ -87,7 +88,7 @@ func GetDepositAddress(input common.Address, xpub string) (output common.Address
// }
// return pk.ToECDSA(), nil
func GetPrivKeyByPriv(xpriv string, path string) (privkey *ecdsa.PrivateKey, err error) {
func GetPrivKeyByPriv(xpriv string, path string) (privkey *btcec.PrivateKey, err error) {
pathList := parsePath(path)
var next *hdkeychain.ExtendedKey
for _, floor := range pathList {
......@@ -103,7 +104,7 @@ func GetPrivKeyByPriv(xpriv string, path string) (privkey *ecdsa.PrivateKey, err
if err != nil {
return
}
return pk.ToECDSA(), nil
return pk, nil
}
func GetPubKeyByPub(xpub string, path string) (pubkey *ecdsa.PublicKey, err error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment