Exemple #1
0
func BitcoinDecodeBase58Address(addr string) (Address, error) {
	b, err := base58.Base582Hex(addr)
	if err != nil {
		return Address{}, err
	}
	return BitcoinAddressFromBytes(b)
}
Exemple #2
0
//extracts a seckey from wallet import format
func SecKeyFromWalletImportFormat(input string) (SecKey, error) {
	b, err := base58.Base582Hex(input)
	if err != nil {
		return SecKey{}, err
	}

	//1+32+1+4
	if len(b) != 38 {
		//log.Printf("len= %v ", len(b))
		return SecKey{}, errors.New("invalid length")
	}
	if b[0] != 0x80 {
		return SecKey{}, errors.New("first byte invalid")
	}

	if b[1+32] != 0x01 {
		return SecKey{}, errors.New("invalid 33rd byte")
	}

	b2 := DoubleSHA256(b[0:34])
	chksum := b[34:38]

	if !bytes.Equal(chksum, b2[0:4]) {
		return SecKey{}, errors.New("checksum fail")
	}

	seckey := b[1:33]
	if len(seckey) != 32 {
		log.Panic("...")
	}
	return NewSecKey(b[1:33]), nil
}