// Sig is signed message, msg is raw message func CheckSig(idKey interfaces.IHash, pub []byte, msg []byte, sig []byte) bool { var pubFix [32]byte var sigFix [64]byte copy(pubFix[:], pub[:32]) copy(sigFix[:], sig[:64]) pre := make([]byte, 0) pre = append(pre, []byte{0x01}...) pre = append(pre, pubFix[:]...) id := primitives.Shad(pre) if id.IsSameAs(idKey) { return ed.VerifyCanonical(&pubFix, msg, &sigFix) } else { return false } }
func TestCheckSig(t *testing.T) { priv := testHelper.NewPrivKey(1) msg := []byte("Hello!") pub := testHelper.PrivateKeyToEDPub(priv) pre := []byte{0x01} pre = append(pre, pub...) id := primitives.Shad(pre) sig := primitives.Sign(priv, msg) if CheckSig(id, pub, msg, sig) == false { t.Error("Valid signature not valid") } sig[0] += 1 if CheckSig(id, pub, msg, sig) == true { t.Error("Invalid signature valid") } }
func (w RCD_1) GetAddress() (interfaces.IAddress, error) { data := []byte{1} data = append(data, w.PublicKey[:]...) return CreateAddress(primitives.Shad(data)), nil }