jagottsicher / myGoBlockchain

🇬🇧 an educational repo to do gather some experience with blockchain technology with Go 🇩🇪 ein Lehr-Repo, um Erfahrungen mit Blockchain-Technology zu machen
Apache License 2.0
0 stars 1 forks source link

problem with signature verification #1

Open Theog75 opened 1 month ago

Theog75 commented 1 month ago

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

Theog75 commented 1 month ago

the json.marshal return empty because none of the transaction struct fields are exported