Beispiel #1
0
func DecodeWIF(encoded string) (version byte, payload []byte, err error) {
	data := base58.DecodeBase58([]byte(encoded))
	if data == nil || len(data) < 25 {
		return 0, nil, fmt.Errorf("Invalid Wallet Import Format data: %#v", encoded)
	}

	check := Digest256(data[0 : len(data)-4])

	version = data[0]
	payload = data[1 : len(data)-4]

	if !bytes.Equal(check[0:4], data[len(data)-4:]) {
		err = fmt.Errorf("Checksum test failed for Wallet Import Format data: %#v", encoded)
	}

	return
}
Beispiel #2
0
func DecodeBitcoinAddress(address string) (addrVersion byte, pubkeyHash []byte, err error) {
	data := base58.DecodeBase58([]byte(address))
	if data == nil {
		return 0, nil, fmt.Errorf("Invalid base58-encoded bitcoin address: %#v", address)
	}
	if len(data) != 25 {
		return 0, nil, fmt.Errorf("Wrong size for bitcoin address: %v bytes", len(data))
	}

	check := Digest256(data[0:21])

	addrVersion = data[0]
	pubkeyHash = data[1:17]

	if !bytes.Equal(check[0:4], data[21:25]) {
		err = fmt.Errorf("Checksum test failed for bitcoin address: %#v", address)
	}

	return
}