func keyFromPrivEd25519(addrType AddrType, priv []byte) (*Key, error) { privKeyBytes := new([64]byte) copy(privKeyBytes[:32], priv) pubKeyBytes := ed25519.MakePublicKey(privKeyBytes) pubKey := account.PubKeyEd25519(*pubKeyBytes) return &Key{ Id: uuid.NewRandom(), Type: KeyType{CurveTypeEd25519, addrType}, Address: pubKey.Address(), PrivateKey: privKeyBytes[:], }, nil }
// Generates a new validator with private key. func GenPrivValidator() *PrivValidator { privKeyBytes := new([64]byte) copy(privKeyBytes[:32], CRandBytes(32)) pubKeyBytes := ed25519.MakePublicKey(privKeyBytes) pubKey := acm.PubKeyEd25519(*pubKeyBytes) privKey := acm.PrivKeyEd25519(*privKeyBytes) return &PrivValidator{ Address: pubKey.Address(), PubKey: pubKey, PrivKey: privKey, LastHeight: 0, LastRound: 0, LastStep: stepNone, filePath: "", } }
func checkCommon(nodeAddr, signAddr, pubkey, addr, amtS, nonceS string) (pub account.PubKey, amt int64, nonce int64, err error) { if amtS == "" { err = fmt.Errorf("input must specify an amount with the --amt flag") return } var pubKeyBytes []byte if pubkey == "" && addr == "" { err = fmt.Errorf("at least one of --pubkey or --addr must be given") return } else if pubkey != "" { if addr != "" { // NOTE: if --addr given byt MINTX_PUBKEY is set, the pubkey still wins // TODO: fix this //logger.Errorln("you have specified both a pubkey and an address. the pubkey takes precedent") } pubKeyBytes, err = hex.DecodeString(pubkey) if err != nil { err = fmt.Errorf("pubkey is bad hex: %v", err) return } } else { // grab the pubkey from eris-keys pubKeyBytes, err = Pub(addr, signAddr) if err != nil { err = fmt.Errorf("failed to fetch pubkey for address (%s): %v", addr, err) return } } if len(pubKeyBytes) == 0 { err = fmt.Errorf("Error resolving public key") return } amt, err = strconv.ParseInt(amtS, 10, 64) if err != nil { err = fmt.Errorf("amt is misformatted: %v", err) } var pubArray [32]byte copy(pubArray[:], pubKeyBytes) pub = account.PubKeyEd25519(pubArray) addrBytes := pub.Address() if nonceS == "" { if nodeAddr == "" { err = fmt.Errorf("input must specify a nonce with the --nonce flag or use --node-addr (or MINTX_NODE_ADDR) to fetch the nonce from a node") return } // fetch nonce from node client := cclient.NewClient(nodeAddr, "HTTP") ac, err2 := client.GetAccount(addrBytes) if err2 != nil { err = fmt.Errorf("Error connecting to node (%s) to fetch nonce: %s", nodeAddr, err2.Error()) return } if ac == nil || ac.Account == nil { err = fmt.Errorf("unknown account %X", addrBytes) return } nonce = int64(ac.Account.Sequence) + 1 } else { nonce, err = strconv.ParseInt(nonceS, 10, 64) if err != nil { err = fmt.Errorf("nonce is misformatted: %v", err) return } } return }