in wallet:
func (t *Transaction) GenerateSignature() *utils.Signature {
m, _ := json.Marshal(t)
fmt.Println("Sign: ", m, t)
h := sha256.Sum256([]byte(m))
// fmt.Println(h)
r, s, _ := ecdsa.Sign(rand.Reader, t.senderPrivateKey, h[:])
return &utils.Signature{R: r, S: s}
}
in blockchain
func (bc *BlockChain) VerifyTransactionSignature(senderPublicKey *ecdsa.PublicKey, s *utils.Signature, t *Transaction) bool {
m, _ := json.Marshal(t)
fmt.Println("Verify:", m, t)
h := sha256.Sum256([]byte(m))
// fmt.Println(h)
return ecdsa.Verify(senderPublicKey, h[:], s.R, s.S)
}
the output of m is same although the transaction in the wallet is different from the transaction in the blockchain
Sign: [123 125] &{0x140001140f0 0x140001140f0 112wEP4zjRf6dqXr7U3VUr4cs4x7egVEwn 18nGYwaj2JC15Ry2zkyzUCZZpv1j3SVEYk 23}
Verify: [123 125] &{112wEP4zjRf6dqXr7U3VUr4cs4x7egVEwn 112wEP4zjRf6dqXr7U3VUr4cs4x7egVEwn 1223}
LC
Add reply
in wallet:
in blockchain
the output of m is same although the transaction in the wallet is different from the transaction in the blockchain
Sign: [123 125] &{0x140001140f0 0x140001140f0 112wEP4zjRf6dqXr7U3VUr4cs4x7egVEwn 18nGYwaj2JC15Ry2zkyzUCZZpv1j3SVEYk 23}
Verify: [123 125] &{112wEP4zjRf6dqXr7U3VUr4cs4x7egVEwn 112wEP4zjRf6dqXr7U3VUr4cs4x7egVEwn 1223}
LC
Add reply