Example #1
0
func (c *OneConnection) HandleAlert(b []byte) {
	var rh [20]byte
	btc.RimpHash(b, rh[:])
	alidx := binary.LittleEndian.Uint64(rh[0:8])

	Alert_access.Lock() // protect access to the map while in the function
	defer Alert_access.Unlock()

	if _, ok := Alerts[alidx]; ok {
		return // already have this one
	}

	a, e := btc.NewAlert(b, AlertPubKey)
	if e != nil {
		println(c.PeerAddr.String(), "- sent us a broken alert:", e.Error())
		if a == nil {
			//println("With apparently broken signature - so ban it!")
			c.DoS("BrokenAlert")
		} else {
			println(hex.EncodeToString(b))
		}
		return
	}

	Alerts[alidx] = a
	NetAlerts <- a.StatusBar
	return
}
Example #2
0
func (c *OneConnection) HandleAlert(b []byte) {
	var rh [20]byte
	btc.RimpHash(b, rh[:])
	alidx := binary.LittleEndian.Uint64(rh[0:8])

	Alert_access.Lock() // protect access to the map while in the function
	defer Alert_access.Unlock()

	if _, ok := Alerts[alidx]; ok {
		return // already have this one
	}

	a, e := btc.NewAlert(b, AlertPubKey)
	if e != nil {
		println(c.PeerAddr.String(), "- sent us a broken alert:", e.Error())
		c.DoS()
		return
	}

	Alerts[alidx] = a
	fmt.Println("\007New alert:", a.StatusBar)
	//ui_show_prompt()
	return
}
Example #3
0
func do_scan_stealth(p string, ignore_prefix bool) {
	sa, _ := btc.NewStealthAddrFromString(p)
	if sa == nil {
		fmt.Println("Specify base58 encoded stealth address")
		return
	}
	if sa.Version != btc.StealthAddressVersion(common.CFG.Testnet) {
		fmt.Println("Incorrect version of the stealth address")
		return
	}
	if len(sa.SpendKeys) != 1 {
		fmt.Println("Currently only single spend keys are supported. This address has", len(sa.SpendKeys))
		return
	}

	//fmt.Println("scankey", hex.EncodeToString(sa.ScanKey[:]))
	if ignore_prefix {
		sa.Prefix = []byte{0}
		fmt.Println("Ignoring Prefix inside the address")
	} else if len(sa.Prefix) == 0 {
		fmt.Println("Prefix not present in the address")
	} else {
		fmt.Println("Prefix", sa.Prefix[0], hex.EncodeToString(sa.Prefix[1:]))
	}

	ds := wallet.FetchStealthKeys()
	if len(ds) == 0 {
		return
	}

	defer func() {
		for i := range ds {
			utils.ClearBuffer(ds[i])
		}
	}() // clear the keys in mem after all

	var d []byte

	for i := range ds {
		if bytes.Equal(btc.PublicFromPrivate(ds[i], true), sa.ScanKey[:]) {
			d = ds[i]
		}
	}

	if d == nil {
		fmt.Println("No matching secret found your wallet/stealth folder")
		return
	}

	var pos []*btc.TxPrevOut
	cs := make(map[uint64][]byte)
	as := make(map[uint64]*btc.BtcAddr)
	var ncnt uint

	common.BlockChain.Unspent.ScanStealth(sa, func(eth, txid []byte, vout uint32, scr []byte) bool {
		if len(scr) == 25 && scr[0] == 0x76 && scr[1] == 0xa9 && scr[2] == 0x14 && scr[23] == 0x88 && scr[24] == 0xac {
			var h160 [20]byte
			//yes := btc.NewUint256(txid).String()=="9cc90ff2528b49dfd9c53e5e90c98a1fd45d577af7f3a9e7a9f8a86b52fb0280"
			c := btc.StealthDH(eth, d)
			spen_exp := btc.DeriveNextPublic(sa.SpendKeys[0][:], c)
			btc.RimpHash(spen_exp, h160[:])
			if bytes.Equal(scr[3:23], h160[:]) {
				po := new(btc.TxPrevOut)
				copy(po.Hash[:], txid)
				po.Vout = vout
				pos = append(pos, po)
				cs[po.UIdx()] = c
				as[po.UIdx()] = btc.NewAddrFromHash160(h160[:], btc.AddrVerPubkey(common.CFG.Testnet))
			}
			ncnt++
			/*fmt.Printf("%s with c=%s",
				btc.NewAddrFromHash160(h160[:], btc.AddrVerPubkey(common.CFG.Testnet)).String(),
				hex.EncodeToString(c))
			fmt.Println()*/
			return true
		} else {
			return false
		}
	})

	fmt.Println(len(pos), "outputs, out of", ncnt, "notifications belonged to our wallet")

	var unsp btc.AllUnspentTx
	for i := range pos {
		po, e := common.BlockChain.Unspent.UnspentGet(pos[i])
		if e != nil {
			println("UnspentGet:", e.Error())
			println("This should not happen - please, report a bug.")
			println("You can probably fix it by launching the client with -rescan")
			os.Exit(1)
		}
		//fmt.Println(btc.NewUint256(pos[i].Hash[:]), pos[i].Vout+1, hex.EncodeToString(cs[pos[i].UIdx()]))
		one := &btc.OneUnspentTx{
			TxPrevOut: *pos[i],
			Value:     po.Value,
			MinedAt:   po.BlockHeight,
			BtcAddr:   as[pos[i].UIdx()],
			StealthC:  cs[pos[i].UIdx()]}
		unsp = append(unsp, one)
	}
	sort.Sort(unsp)
	os.RemoveAll("balance")
	os.MkdirAll("balance/", 0770)
	utxt, _ := os.Create("balance/unspent.txt")
	fmt.Print(wallet.DumpBalance(unsp, utxt, true, false))
}
Example #4
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")
	}
}