Esempio n. 1
0
func main() {
	flag.Parse()
	if *help {
		flag.PrintDefaults()
		return
	}

	msg, _ := ioutil.ReadAll(os.Stdin)
	if len(msg) == 0 {
		return
	}

	if *decode {
		res := btc.Decodeb58(strings.Trim(string(msg), " \t\n\r"))
		if *binary {
			os.Stdout.Write(res)
		} else {
			fmt.Println(hex.EncodeToString(res))
		}
	} else {
		fmt.Println(btc.Encodeb58(msg))
	}
}
Esempio n. 2
0
func load_others() {
	f, e := os.Open(RawKeysFilename)
	if e == nil {
		defer f.Close()
		td := bufio.NewReader(f)
		for {
			li, _, _ := td.ReadLine()
			if li == nil {
				break
			}
			if len(li) == 0 {
				continue
			}
			pk := strings.SplitN(strings.Trim(string(li), " "), " ", 2)
			if pk[0][0] == '#' {
				continue // Just a comment-line
			}

			pkb := btc.Decodeb58(pk[0])

			if pkb == nil {
				println("Decodeb58 failed:", pk[0])
				continue
			}

			if len(pkb) < 6 {
				println("Syntax error in the raw keys file:", pk[0])
				continue
			}

			if len(pkb) != 37 && len(pkb) != 38 {
				println(pk[0][:6], "has wrong key", len(pkb))
				println(hex.EncodeToString(pkb))
				continue
			}

			if pkb[0] != AddrVerSecret() {
				println(pk[0][:6], "has version", pkb[0], "while we expect", AddrVerSecret())
				fmt.Println("You may want to play with -t or -ltc switch")
				continue
			}

			var sh [32]byte
			var compr bool

			if len(pkb) == 37 {
				// old/uncompressed key
				sh = btc.Sha2Sum(pkb[0:33])
				if !bytes.Equal(sh[:4], pkb[33:37]) {
					println(pk[0][:6], "checksum error")
					continue
				}
				compr = false
			} else {
				if pkb[33] != 1 {
					println(pk[0][:6], "a key of length 38 bytes must be compressed")
					continue
				}

				sh = btc.Sha2Sum(pkb[0:34])
				if !bytes.Equal(sh[:4], pkb[34:38]) {
					println(pk[0][:6], "checksum error")
					continue
				}
				compr = true
			}

			key := pkb[1:33]
			pub := btc.PublicFromPrivate(key, compr)
			if pub == nil {
				println("PublicFromPrivate failed")
				os.Exit(1)
			}

			priv_keys = append(priv_keys, key)
			compressed_key = append(compressed_key, compr)
			publ_addrs = append(publ_addrs, btc.NewAddrFromPubkey(pub, AddrVerPubkey()))
			if len(pk) > 1 {
				labels = append(labels, pk[1])
			} else {
				labels = append(labels, fmt.Sprint("Other ", len(priv_keys)))
			}
		}
		if *verbose {
			fmt.Println(len(priv_keys), "keys imported from", RawKeysFilename)
		}
	} else {
		if *verbose {
			fmt.Println("You can also have some dumped (b58 encoded) priv keys in file", RawKeysFilename)
		}
	}
}