2023-03-02 01:05:53 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2024-06-24 21:55:40 +00:00
|
|
|
errorsmod "cosmossdk.io/errors"
|
2023-03-02 01:05:53 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2024-06-24 21:55:40 +00:00
|
|
|
"github.com/cosmos/go-bip39"
|
2023-03-02 01:05:53 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SdkToEvmAddress(addr sdk.AccAddress) common.Address {
|
|
|
|
return common.BytesToAddress(addr.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
func EvmToSdkAddress(addr common.Address) sdk.AccAddress {
|
|
|
|
return sdk.AccAddress(addr.Bytes())
|
|
|
|
}
|
2024-06-24 21:55:40 +00:00
|
|
|
|
|
|
|
// RandomMnemonic generates a random BIP39 mnemonic from 128 bits of entropy
|
|
|
|
func RandomMnemonic() (string, error) {
|
|
|
|
entropy, err := bip39.NewEntropy(128)
|
|
|
|
if err != nil {
|
|
|
|
return "", errorsmod.Wrap(err, "failed to generate entropy for new mnemonic")
|
|
|
|
}
|
|
|
|
return bip39.NewMnemonic(entropy)
|
|
|
|
}
|