예제 #1
0
파일: api.go 프로젝트: skycoin/skycoin
// Generating secret key, address, public key by given
// GET/POST
// 	bc - bool - is bitcoin type (optional) - default: true
//	n - int - Generation count (optional) - default: 1
//	s - bool - is hide secret key (optional) - default: false
//	seed - string - seed hash
func apiCreateAddressHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {

		var seed string = r.FormValue("seed")
		var err error

		if seed == "" {
			wh.Error400(w, "Empty seed")
			return
		}

		isBitcoin, err = strconv.ParseBool(r.FormValue("bc"))
		if err != nil {
			isBitcoin = true
		}

		genCount, err := strconv.Atoi(r.FormValue("n"))
		if err != nil {
			genCount = 1
		}

		hideSecKey, err = strconv.ParseBool(r.FormValue("s"))
		if err != nil {
			hideSecKey = false
		}

		wallet := Wallet{
			Meta:    make(map[string]string), //map[string]string
			Entries: make([]KeyEntry, genCount),
		}

		if isBitcoin == false {
			wallet.Meta = map[string]string{"coin": "skycoin"}
		} else {
			wallet.Meta = map[string]string{"coin": "bitcoin"}
		}

		wallet.Meta["seed"] = seed

		seckeys := cipher.GenerateDeterministicKeyPairs([]byte(seed), genCount)

		for i, sec := range seckeys {
			pub := cipher.PubKeyFromSecKey(sec)
			wallet.Entries[i] = getKeyEntry(pub, sec)
		}

		ret := wallet

		wh.SendOr404(w, ret)
	}
}
예제 #2
0
func main() {
	registerFlags()
	parseFlags()

	w := Wallet{
		Meta:    make(map[string]string), //map[string]string
		Entries: make([]KeyEntry, genCount),
	}

	if BitcoinAddress == false {
		w.Meta = map[string]string{"coin": "skycoin"}
	} else {
		w.Meta = map[string]string{"coin": "bitcoin"}
	}

	if seed == "" { //generate a new seed, as hex string
		seed = cipher.SumSHA256(cipher.RandByte(1024)).Hex()
	}

	w.Meta["seed"] = seed

	seckeys := cipher.GenerateDeterministicKeyPairs([]byte(seed), genCount)

	for i, sec := range seckeys {
		pub := cipher.PubKeyFromSecKey(sec)
		w.Entries[i] = getKeyEntry(pub, sec)
	}

	output, err := json.MarshalIndent(w, "", "    ")
	if err != nil {
		fmt.Printf("Error formating wallet to JSON. Error : %s\n", err.Error())
		return
	}
	fmt.Printf("%s\n", string(output))

}