Example #1
0
func FindStealthSecret(sa *btc.StealthAddr) (d []byte) {
	for i := range StealthSecrets {
		if bytes.Equal(btc.PublicFromPrivate(StealthSecrets[i], true), sa.ScanKey[:]) {
			return StealthSecrets[i]
		}
	}
	for i := range ArmedStealthSecrets {
		if bytes.Equal(btc.PublicFromPrivate(ArmedStealthSecrets[i], true), sa.ScanKey[:]) {
			return ArmedStealthSecrets[i]
		}
	}
	return
}
Example #2
0
func listarmkeys(p string) {
	if p != "seed" {
		if len(wallet.StealthSecrets) > 0 {
			fmt.Println("Persistent secret scan keys:")
			for i := range wallet.StealthSecrets {
				pk := btc.PublicFromPrivate(wallet.StealthSecrets[i], true)
				fmt.Print(" #", i, "  ", hex.EncodeToString(pk))
				if p == "addr" {
					fmt.Print("  ", btc.NewAddrFromPubkey(pk, btc.AddrVerPubkey(common.Testnet)).String())
				}
				fmt.Println()
			}
		} else {
			fmt.Println("You have no persistent secret scan keys")
		}
	}
	if p != "file" {
		if len(wallet.ArmedStealthSecrets) > 0 {
			fmt.Println("Volatile secret scan keys:")
			for i := range wallet.ArmedStealthSecrets {
				pk := btc.PublicFromPrivate(wallet.ArmedStealthSecrets[i], true)
				fmt.Print(" #", i, "  ", hex.EncodeToString(pk))
				if p == "addr" {
					fmt.Print("  ", btc.NewAddrFromPubkey(pk, btc.AddrVerPubkey(common.Testnet)).String())
				}
				if p == "save" {
					fn := common.GocoinHomeDir + "wallet/stealth/" + hex.EncodeToString(pk)
					if fi, er := os.Stat(fn); er == nil && fi.Size() >= 32 {
						fmt.Print("  already on disk")
					} else {
						ioutil.WriteFile(fn, wallet.ArmedStealthSecrets[i], 0600)
						fmt.Print("  saved")
					}
					sys.ClearBuffer(wallet.ArmedStealthSecrets[i])
				}
				fmt.Println()
			}
		} else {
			fmt.Println("You have no volatile secret scan keys")
		}
	}
	if p == "save" {
		wallet.ArmedStealthSecrets = nil
		wallet.FetchStealthKeys()
	}
}
Example #3
0
func arm_stealth(p string) {
	var buf, b2 [256]byte

	create := p != ""

	fmt.Print("Enter seed password of the stealth key (empty line to abort) : ")
	le := sys.ReadPassword(buf[:])
	if le <= 0 {
		fmt.Println("Aborted")
		return
	}
	if create {
		fmt.Print("Re-enter the seed password : "******"The passwords you entered do not match")
			return
		}
	}

	nw := make([]byte, 32)
	btc.ShaHash(buf[:le], nw) // seed
	sys.ClearBuffer(buf[:le])
	btc.ShaHash(nw, nw) // 1st key
	wallet.ArmedStealthSecrets = append(wallet.ArmedStealthSecrets, nw)
	if create {
		fmt.Println("You have created a new stealth scan-key. Make sure to not forget this password!")
		pk := btc.PublicFromPrivate(nw, true)
		fmt.Println("Public hexdump:", hex.EncodeToString(pk))
		fmt.Println(" Go to your wallet machine and execute:")
		fmt.Println("   wallet -scankey", hex.EncodeToString(pk), "-prefix 0")
		fmt.Println("   (change the prefix to a different value if you want)")
	}
	fmt.Println("Stealth key number", len(wallet.ArmedStealthSecrets)-1, "has been stored in memory")
	fmt.Println("Reloading the current wallet...")
	usif.ExecUiReq(&usif.OneUiReq{Handler: func(p string) {
		wallet.LoadWallet(wallet.MyWallet.FileName)
	}})
	show_prompt = false
}
Example #4
0
// Generate a new stealth address
func new_stealth_address(prv_key []byte) {
	sk, er := hex.DecodeString(*scankey)
	if er != nil {
		println(er.Error())
		cleanExit(1)
	}
	if len(sk) != 33 || sk[0] != 2 && sk[0] != 3 {
		println("scankey must be a compressed public key (33 bytes long)")
		cleanExit(1)
	}

	if *prefix > 16 {
		if *prefix > 24 {
			fmt.Println("The stealth prefix cannot be bigger than 24", *prefix)
			cleanExit(1)
		}
		fmt.Println("WARNING: You chose a prefix length of", *prefix)
		fmt.Println(" Long prefixes endanger anonymity of stealth address.")
	}

	pub := btc.PublicFromPrivate(prv_key, true)
	if pub == nil {
		println("PublicFromPrivate error 2")
		cleanExit(1)
	}

	sa := new(btc.StealthAddr)
	sa.Version = btc.StealthAddressVersion(testnet)
	sa.Options = 0
	copy(sa.ScanKey[:], sk)
	sa.SpendKeys = make([][33]byte, 1)
	copy(sa.SpendKeys[0][:], pub)
	sa.Sigs = 1
	sa.Prefix = make([]byte, 1+(byte(*prefix)+7)>>3)
	if *prefix > 0 {
		sa.Prefix[0] = byte(*prefix)
		rand.Read(sa.Prefix[1:])
	}
	fmt.Println(sa.String())
}