Example #1
0
func UncompressPubkey(pubkey []byte) []byte {
	if VerifyPubkey(pubkey) != 1 {
		log.Panic("cannot uncompress invalid pubkey")
		return nil
	}

	var pub_xy secp.XY
	err := pub_xy.ParsePubkey(pubkey)
	if err == false {
		log.Panic("ERROR: impossible, pubkey parse fail")
	}

	var pubkey2 []byte = pub_xy.BytesUncompressed() //uncompressed
	if pubkey2 == nil {
		log.Panic("ERROR: pubkey, uncompression fail")
		return nil
	}

	return pubkey2
}
Example #2
0
//Rename ChkPubkeyValidity
// returns 1 on success
func VerifyPubkey(pubkey []byte) int {
	if len(pubkey) != 33 {
		//log.Printf("Seck256k1, VerifyPubkey, pubkey length invalid")
		return -1
	}

	if secp.PubkeyIsValid(pubkey) != 1 {
		return -3 //tests parse and validity
	}

	var pubkey1 secp.XY
	ret := pubkey1.ParsePubkey(pubkey)

	if ret == false {
		return -2 //invalid, parse fail
	}
	//fails for unknown reason
	//TODO: uncomment
	if pubkey1.IsValid() == false {
		return -4 //invalid, validation fail
	}
	return 1 //valid
}