//StringToAddress returns the Bitcoin address of a base58-encoded extended key. func StringAddress(data string) (string, error) { w, err := StringWallet(data) if err != nil { return "", err } // WTF the testvectors expect address made from uncompreessed public key? tnet := w.Prefix == TestPublic || w.Prefix == TestPrivate if false { return NewAddrFromPubkey(w.Key, AddrVerPubkey(tnet)).String(), nil } else { var xy secp256k1.XY xy.ParsePubkey(w.Key) return NewAddrFromPubkey(xy.Bytes(false), AddrVerPubkey(tnet)).String(), nil } }
// Verifies consistency of a serialized HD address func ByteCheck(dbin []byte) error { // check proper length if len(dbin) != 82 { return errors.New("ByteCheck: Unexpected length") } // check for correct Public or Private Prefix vb := binary.BigEndian.Uint32(dbin[:4]) if vb != Public && vb != Private && vb != TestPublic && vb != TestPrivate { return errors.New("ByteCheck: Unexpected Prefix") } // if Public, check x coord is on curve if vb == Public || vb == TestPublic { var xy secp256k1.XY xy.ParsePubkey(dbin[45:78]) if !xy.IsValid() { return errors.New("ByteCheck: Invalid public key") } } return nil }