status-go/services/utils/utils.go

44 lines
1.3 KiB
Go

package utils
import (
"math/big"
"strings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/status-im/status-go/account"
"github.com/status-im/status-go/api/multiformat"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
prot_common "github.com/status-im/status-go/protocol/common"
)
func GetSigner(chainID uint64, accountsManager *account.GethManager, keyStoreDir string, from types.Address, password string) bind.SignerFn {
return func(addr common.Address, tx *ethTypes.Transaction) (*ethTypes.Transaction, error) {
selectedAccount, err := accountsManager.VerifyAccountPassword(keyStoreDir, from.Hex(), password)
if err != nil {
return nil, err
}
s := ethTypes.NewLondonSigner(new(big.Int).SetUint64(chainID))
return ethTypes.SignTx(tx, s, selectedAccount.PrivateKey)
}
}
func DeserializePublicKey(compressedKey string) (types.HexBytes, error) {
rawKey, err := multiformat.DeserializePublicKey(compressedKey, "f")
if err != nil {
return nil, err
}
secp256k1Code := "fe701"
pubKeyBytes := "0x" + strings.TrimPrefix(rawKey, secp256k1Code)
pubKey, err := prot_common.HexToPubkey(pubKeyBytes)
if err != nil {
return nil, err
}
return crypto.CompressPubkey(pubKey), nil
}