Skip to content

Commit 5c84f72

Browse files
author
David Case
committed
fix message version
1 parent 8b88589 commit 5c84f72

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ linters:
336336
- dogsled
337337
# - revive
338338
- prealloc
339-
- exportloopref
339+
- copyloopvar
340340
- exhaustive
341341
- sqlclosecheck
342342
- nolintlint

message/encrypted.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
// BRC-78: https://github.com/bitcoin-sv/BRCs/blob/master/peer-to-peer/0078.md
14-
const VERSION = "42421033"
14+
const VERSION = "42423301"
1515

1616
var VERSION_BYTES = []byte{0x42, 0x42, 0x10, 0x33}
1717

message/signed_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package message
22

33
import (
4+
"crypto/rand"
5+
"math/big"
46
"testing"
57

68
ec "github.com/bitcoin-sv/go-sdk/primitives/ec"
@@ -48,3 +50,27 @@ func TestSignedMessage(t *testing.T) {
4850
})
4951

5052
}
53+
54+
func TestEdgeCases(t *testing.T) {
55+
signingPriv, _ := ec.PrivateKeyFromBytes([]byte{15})
56+
57+
message := make([]byte, 32)
58+
for i := 0; i < 10000; i++ {
59+
rand.Read(message)
60+
signature, err := signingPriv.Sign(message)
61+
require.NoError(t, err)
62+
63+
// Manually set R and S to edge case values (e.g., highest bit set).
64+
// These values will require padding when encoded in DER.
65+
signature.R = big.NewInt(0x80) // Example: 128, which in binary is 10000000
66+
signature.S = new(big.Int).SetBytes([]byte{0x80, 0x00, 0x00, 0x01}) // Example edge case
67+
68+
signatureSerialized := signature.Serialize()
69+
signatureDER, err := signature.ToDER()
70+
require.NoError(t, err)
71+
72+
require.Equal(t, signatureSerialized, signatureDER)
73+
require.Equal(t, len(signatureSerialized), len(signatureDER))
74+
t.Logf("Signature serialized: %d %x - %d %x\n", len(signatureDER), signatureDER, len(signatureSerialized), signatureSerialized)
75+
}
76+
}

0 commit comments

Comments
 (0)