Beispiel #1
0
//recovers the public key from the signature
//recovery of pubkey means correct signature
func RecoverPubkey(msg []byte, sig []byte) []byte {
	if len(sig) != 65 {
		log.Panic()
	}

	var recid int = int(sig[64])

	pubkey, ret := secp.RecoverPublicKey(
		sig[0:64],
		msg,
		recid)

	if ret != 1 {
		log.Printf("RecoverPubkey: code %s", ret)
		return nil
	}
	//var pubkey2 []byte = pubkey1.Bytes() //compressed

	if pubkey == nil {
		log.Panic("ERROR: impossible, pubkey nil and ret ==1")
	}
	if len(pubkey) != 33 {
		log.Panic("pubkey length wrong")
	}

	return pubkey
	//nonce1.SetBytes(nonce_seed)

}
//recovers the public key from the signature
//recovery of pubkey means correct signature
func _RecoverPubkey(msg []byte, sig []byte) []byte {
	if len(sig) != 65 {
		log.Panic()
	}

	var recid int = int(sig[64])
	//var msg1 secp.Number

	//var pubkey1 secp.XY

	//msg1.SetBytes(msg)
	//sig1.SetBytes(sig)

	//var sig1 secp.Signature
	//sig1.ParseBytes(sig[0:64])

	//if ret != 1 {
	//log.Panic("secp256k1, RecoverPubKey, recovery failed")
	//	log.Fatal("Parse Bytes Fail")
	//	return nil
	//}

	pubkey, ret := secp.RecoverPublicKey(
		sig[0:64],
		msg,
		recid)

	/*
		ret := secp.RecoverPublicKey(
			sig1.R.Bytes(),
			sig1.S.Bytes(),
			msg,
			recid,
			&pubkey1)
	*/
	if ret != 1 {
		log.Printf("RecoverPubkey: code %s", ret)
		return nil
	}
	//var pubkey2 []byte = pubkey1.Bytes() //compressed

	if pubkey == nil {
		log.Panic("ERROR: impossible, pubkey nil and ret ==1")
	}
	if len(pubkey) != 33 {
		log.Panic("pubkey length wrong")
	}

	return pubkey
	//nonce1.SetBytes(nonce_seed)

}