Exemplo n.º 1
0
// Input the password (that is the secret seed to your wallet)
func getseed(seed []byte) bool {
	var pass [1024]byte
	var n int
	var e error
	var f *os.File

	if !*ask4pass {
		f, e = os.Open(PassSeedFilename)
		if e == nil {
			n, e = f.Read(pass[:])
			f.Close()
			if n <= 0 {
				return false
			}
			goto calc_seed
		}

		fmt.Println("Seed file", PassSeedFilename, "not found")
	}

	fmt.Print("Enter your wallet's seed password: "******"Re-enter the seed password (to be sure): ")
			var pass2 [1024]byte
			p2len := utils.ReadPassword(pass2[:])
			if p2len != n || !bytes.Equal(pass[:n], pass2[:p2len]) {
				utils.ClearBuffer(pass2[:p2len])
				println("The two passwords you entered do not match")
				return false
			}
			utils.ClearBuffer(pass2[:p2len])
		}
		// Maybe he wants to save the password?
		if ask_yes_no("Save the password on disk, so you won't be asked for it later?") {
			e = ioutil.WriteFile(PassSeedFilename, pass[:n], 0600)
			if e != nil {
				fmt.Println("WARNING: Could not save the password", e.Error())
			}
		}
	}
calc_seed:
	for i := 0; i < n; i++ {
		if pass[i] < ' ' || pass[i] > 126 {
			fmt.Println("WARNING: Your secret contains non-printable characters")
			break
		}
	}
	btc.ShaHash(pass[:n], seed)
	utils.ClearBuffer(pass[:n])
	return true
}
Exemplo n.º 2
0
// Get the secret seed and generate "*keycnt" key pairs (both private and public)
func make_wallet() {
	var lab string

	if *testnet {
		verbyte = 0x6f
		privver = 0xef
	} else {
		// verbyte is be zero by definition
		privver = 0x80
	}
	load_others()

	pass := getpass()
	seed_key := make([]byte, 32)
	btc.ShaHash([]byte(pass), seed_key)
	if *waltype == 3 {
		lab = "TypC"
	} else if *waltype == 2 {
		if *type2sec != "" {
			d, e := hex.DecodeString(*type2sec)
			if e != nil {
				println("t2sec error:", e.Error())
				os.Exit(1)
			}
			type2_secret = new(big.Int).SetBytes(d)
		} else {
			var buf [32]byte
			btc.ShaHash([]byte(pass+pass), buf[:])
			type2_secret = new(big.Int).SetBytes(buf[:])
		}
		lab = "TypB"
	} else {
		lab = "TypA"
	}
	if pass != "" {
		if *verbose {
			fmt.Println("Generating", *keycnt, "keys, version", verbyte, "...")
		}
		for i := uint(0); i < *keycnt; {
			prv_key := make([]byte, 32)
			if *waltype == 3 {
				btc.ShaHash(seed_key, prv_key)
				seed_key = append(seed_key, byte(i))
			} else if *waltype == 2 {
				seed_key = btc.DeriveNextPrivate(new(big.Int).SetBytes(seed_key), type2_secret).Bytes()
				copy(prv_key, seed_key)
			} else {
				btc.ShaHash(seed_key, prv_key)
				copy(seed_key, prv_key)
			}
			priv_keys = append(priv_keys, prv_key)
			pub, er := btc.PublicFromPrivate(prv_key, !*uncompressed)
			if er == nil {
				publ_addrs = append(publ_addrs, btc.NewAddrFromPubkey(pub, verbyte))
				labels = append(labels, fmt.Sprint(lab, " ", i+1))
				i++
			} else {
				println("PublicFromPrivate:", er.Error())
			}
		}
		if *verbose {
			fmt.Println("Private keys re-generated")
		}
	}
}
Exemplo n.º 3
0
// Get the secret seed and generate "*keycnt" key pairs (both private and public)
func make_wallet() {
	var lab string

	if *testnet {
		verbyte = 0x6f
		privver = 0xef
	} else {
		// verbyte is be zero by definition
		privver = 0x80
	}
	load_others()

	seed_key := make([]byte, 32)
	if !getseed(seed_key) {
		os.Exit(0)
	}

	defer func() {
		utils.ClearBuffer(seed_key)
	}()

	if *waltype == 3 {
		lab = "TypC"
	} else if *waltype == 2 {
		if *type2sec != "" {
			d, e := hex.DecodeString(*type2sec)
			if e != nil {
				println("t2sec error:", e.Error())
				os.Exit(1)
			}
			type2_secret = d
		} else {
			type2_secret = make([]byte, 20)
			btc.RimpHash(seed_key, type2_secret)
		}
		lab = "TypB"
	} else {
		lab = "TypA"
	}

	if *verbose {
		fmt.Println("Generating", *keycnt, "keys, version", verbyte, "...")
	}
	for i := uint(0); i < *keycnt; {
		prv_key := make([]byte, 32)
		if *waltype == 3 {
			btc.ShaHash(seed_key, prv_key)
			seed_key = append(seed_key, byte(i))
		} else if *waltype == 2 {
			seed_key = btc.DeriveNextPrivate(seed_key, type2_secret)
			copy(prv_key, seed_key)
		} else {
			btc.ShaHash(seed_key, prv_key)
			copy(seed_key, prv_key)
		}
		priv_keys = append(priv_keys, prv_key)
		if *scankey != "" {
			new_stealth_address(prv_key)
			return
		}

		// for stealth keys
		if i == 0 {
			copy(first_seed[:], prv_key)
		}
		compressed_key = append(compressed_key, !*uncompressed)
		pub := btc.PublicFromPrivate(prv_key, !*uncompressed)
		if pub != nil {
			adr := btc.NewAddrFromPubkey(pub, verbyte)

			if *pubkey != "" && *pubkey == adr.String() {
				fmt.Println(adr.String(), "=>", hex.EncodeToString(pub))
				return
			}
			publ_addrs = append(publ_addrs, adr)
			labels = append(labels, fmt.Sprint(lab, " ", i+1))
			i++
		} else {
			println("PublicFromPrivate error 3")
		}
	}
	if *verbose {
		fmt.Println("Private keys re-generated")
	}
}