main_test.go
TEXT FILE604 B · Public source code for developers, search crawlers and AI agents
1package main
2
3import (
4 "bytes"
5 "crypto/sha256"
6 "github.com/btcsuite/btcd/btcec/v2/ecdsa"
7 "testing"
8)
9
10func TestSignature(t *testing.T) {
11 k := fixture()
12 h := sha256.Sum256([]byte("demo"))
13 s := ecdsa.Sign(k, h[:])
14 b := s.Serialize()
15 if !bytes.Equal(b, ecdsa.Sign(k, h[:]).Serialize()) {
16 t.Fatal("not deterministic")
17 }
18 p, e := ecdsa.ParseDERSignature(b)
19 if e != nil || !p.Verify(h[:], k.PubKey()) {
20 t.Fatal("verify failed")
21 }
22 h[0] ^= 1
23 if p.Verify(h[:], k.PubKey()) {
24 t.Fatal("tamper accepted")
25 }
26 if _, e := ecdsa.ParseDERSignature([]byte{0x30}); e == nil {
27 t.Fatal("bad DER")
28 }
29}Read-only source · Select a line number to link directly · Raw download above
