func main() {

	privatekey := make([]byte, 32)
	_, err := rand.Read(privatekey)
	if err == nil {
		privAddr := factoid.NewAddress(privatekey)

		privHuman := factoid.ConvertFctPrivateToUserStr(privAddr)
		fmt.Printf("New Factoid Private Key: %v\n", privHuman)

		pub, priv, err := wallet.GenerateKeyFromPrivateKey(privatekey)
		if err != nil {
			panic(err)
		}

		we := new(wallet.WalletEntry)
		we.AddKey(pub, priv)
		we.SetName([]byte("test"))
		we.SetRCD(factoid.NewRCD_1(pub))
		we.SetType("fct")

		address, _ := we.GetAddress()

		adr := factoid.ConvertFctAddressToUserStr(address)

		fmt.Printf("New Factoid Address:     %v\n", adr)
	} else {
		fmt.Printf("error\n")
	}

}
Exemple #2
0
// ExportKey <name>
func (ExportKey) Execute(state IState, args []string) error {

	if len(args) != 2 {
		return fmt.Errorf("Invalid Parameters")
	}
	name := args[1]

	weblk := state.GetFS().GetDB().GetRaw([]byte(fct.W_NAME), []byte(name))
	if weblk == nil {
		return fmt.Errorf("Unknown address.  Check that you spelled the name correctly")
	}
	we := weblk.(wallet.IWalletEntry)
	public, err := we.GetAddress()
	if err != nil {
		return err
	}
	private := we.GetPrivKey(0)
	adrtype := we.GetType()

	binPublic := hex.EncodeToString(public.Bytes())
	binPrivate := hex.EncodeToString(private[:32])
	var usrPublic, usrPrivate string
	if adrtype == "fct" {
		usrPublic = fct.ConvertFctAddressToUserStr(fct.NewAddress(public.Bytes()))
		usrPrivate = fct.ConvertFctPrivateToUserStr(fct.NewAddress(private[:32]))
	} else {
		usrPublic = fct.ConvertECAddressToUserStr(fct.NewAddress(public.Bytes()))
		usrPrivate = fct.ConvertECPrivateToUserStr(fct.NewAddress(private[:32]))
	}

	fmt.Println("Private Key:")
	fmt.Println("  ", usrPrivate)
	fmt.Println("  ", binPrivate)
	fmt.Println("Public Key:")
	fmt.Println("  ", usrPublic)
	fmt.Println("  ", binPublic)
	return nil
}