-
-
Save intl-man/2a00c96be3d710e6104381792316d501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"github.com/cosmos/cosmos-sdk/crypto/keys" | |
"github.com/cosmos/cosmos-sdk/crypto/keys/hd" | |
sdk "github.com/cosmos/cosmos-sdk/types" | |
) | |
const ( | |
AccountAddressPrefix = "sif" | |
) | |
var ( | |
AccountPubKeyPrefix = AccountAddressPrefix + "pub" | |
hdpath = *hd.NewFundraiserParams(0, sdk.CoinType, 0) | |
) | |
type RelayerChain struct { | |
mnemonic string | |
kb keys.Keybase | |
} | |
func NewRelayerChain(mnemonic string) *RelayerChain { | |
return &RelayerChain{ | |
mnemonic: mnemonic, | |
} | |
} | |
func (r *RelayerChain) SetConfig() { | |
config := sdk.GetConfig() | |
config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix) | |
config.Seal() | |
} | |
func (r *RelayerChain) GenerateKeyStore() { | |
r.kb = keys.NewInMemory(keys.WithSupportedAlgosLedger([]keys.SigningAlgo{keys.Secp256k1, keys.Ed25519})) | |
} | |
func (r *RelayerChain) GetAccountFromMnemonic() keys.Info { | |
account, err := r.kb.CreateAccount("validator", r.mnemonic, "", "password", hdpath.String(), keys.Secp256k1) | |
if err != nil { | |
panic(err) | |
} | |
return account | |
} | |
func (r *RelayerChain) Address() { | |
account := r.GetAccountFromMnemonic() | |
fmt.Println(account.GetAddress().String()) | |
} | |
func (r *RelayerChain) Sign() { | |
pl, pk, err := r.kb.Sign("validator", "password", []byte("this is the end...")) | |
if err != nil { | |
panic(err) | |
} | |
currentPubKey, _ := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, r.GetAccountFromMnemonic().GetPubKey()) | |
fmt.Printf("Account PubKey: %s\n", currentPubKey) | |
signedPubKey, _ := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pk) | |
fmt.Printf("Signature PubKey: %s\n", signedPubKey) | |
fmt.Println(pl) | |
} | |
func main() { | |
mnemonic := flag.String("m", "", "the key mnemonic") | |
flag.Parse() | |
rc := NewRelayerChain(*mnemonic) | |
rc.SetConfig() | |
rc.GenerateKeyStore() | |
rc.Address() | |
//rc.Sign() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment