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")
	}

}
Пример #2
0
func (w *WalletEntry) AddKey(public, private []byte) {
	if len(public) != fct.ADDRESS_LENGTH || (len(private) != fct.ADDRESS_LENGTH &&
		len(private) != fct.PRIVATE_LENGTH) {
		panic(fmt.Sprintf("Bad Keys presented to AddKey.  Should not happen."+
			"\n  public: %x\n  private: %x", public, private))
	}
	pu := make([]byte, fct.ADDRESS_LENGTH, fct.ADDRESS_LENGTH)
	pr := make([]byte, fct.PRIVATE_LENGTH, fct.PRIVATE_LENGTH)
	copy(pu, public)
	copy(pr[:32], private)
	copy(pr[32:], public)
	w.public = append(w.public, pu)
	w.private = append(w.private, pr)

	w.rcd = fct.NewRCD_1(pu)
}
Пример #3
0
func main() {

	r := bufio.NewScanner(os.Stdin)

	fmt.Print("Enter 12 words from Koinify here: ")
	r.Scan()
	line := r.Text()
	args := strings.Fields(string(line))

	if len(args) == 12 {

		mnemonic := ""
		for _, v := range args {
			v = strings.ToLower(v)
			mnemonic = mnemonic + v + " "
		}
		mnemonic = strings.TrimSpace(mnemonic)
		private, err := wallet.MnemonicStringToPrivateKey(mnemonic)
		if err != nil {
			fmt.Print("\n\nThere was a problem with the 12 words you entered. Please check spelling against this list:\n")
			fmt.Print("https://github.com/FactomProject/go-bip39/blob/master/wordlist.go\n\n\n\n")
			panic(err)
		}
		pub, priv, err := wallet.GenerateKeyFromPrivateKey(private)
		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("\nFactoid Address: %v\n", adr)
		fmt.Printf("\nCheck your balance at http://explorer.factom.org/\n")
	} else {
		fmt.Printf("\n\nError: 12 and only 12 words are expected.\n")
	}

}
Пример #4
0
func (w *SCWallet) AddInput(trans fct.ITransaction, address fct.IAddress, amount uint64) error {
	// Check if this is an address we know.
	we, adr, err := w.getWalletEntry([]byte(fct.W_RCD_ADDRESS_HASH), address)
	// If it isn't, we assume the user knows what they are doing.
	if we == nil || err != nil {
		rcd := fct.NewRCD_1(address.Bytes())
		trans.AddRCD(rcd)
		adr, err := rcd.GetAddress()
		if err != nil {
			return err
		}
		trans.AddInput(fct.CreateAddress(adr), amount)
	} else {
		trans.AddRCD(we.GetRCD())
		trans.AddInput(fct.CreateAddress(adr), amount)
	}

	return nil
}
Пример #5
0
func (w *SCWallet) AddKeyPair(addrtype string, name []byte, pub []byte, pri []byte, generateRandomIfAddressPresent bool) (address fct.IAddress, err error) {

	we := new(WalletEntry)

	nm := w.db.GetRaw([]byte(fct.W_NAME), name)
	if nm != nil {
		str := fmt.Sprintf("The name '%s' already exists. Duplicate names are not supported", string(name))
		return nil, fmt.Errorf(str)
	}

	// Make sure we have not generated this pair before;  Keep
	// generating until we have a unique pair.
	for w.db.GetRaw([]byte(fct.W_ADDRESS_PUB_KEY), pub) != nil {
		if generateRandomIfAddressPresent {
			pub, pri, err = w.generateKey()
			if err != nil {
				return nil, err
			}
		} else {
			return nil, fmt.Errorf("Address already exists in the wallet")
		}
	}

	we.AddKey(pub, pri)
	we.SetName(name)
	we.SetRCD(fct.NewRCD_1(pub))
	if addrtype == "fct" {
		we.SetType("fct")
	} else {
		we.SetType("ec")
	}
	//
	address, _ = we.GetAddress()
	w.db.PutRaw([]byte(fct.W_RCD_ADDRESS_HASH), address.Bytes(), we)
	w.db.PutRaw([]byte(fct.W_ADDRESS_PUB_KEY), pub, we)
	w.db.PutRaw([]byte(fct.W_NAME), name, we)

	return
}