Skip to content

Commit

Permalink
change compressed to false in sign, updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Nov 1, 2020
1 parent 7f3f889 commit 003f7f9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
6 changes: 3 additions & 3 deletions sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/base64"
"errors"
"fmt"

"github.com/bitcoinsv/bsvd/bsvec"
"github.com/bitcoinsv/bsvd/chaincfg/chainhash"
Expand All @@ -30,7 +29,7 @@ func SignMessage(privateKey string, message string) (string, error) {

// Create the hash
messageHash := chainhash.DoubleHashB(buf.Bytes())
fmt.Printf("%x", messageHash)
// fmt.Printf("%x", messageHash)
// Get the private key
var ecdsaPrivateKey *bsvec.PrivateKey
if ecdsaPrivateKey, err = PrivateKeyFromString(privateKey); err != nil {
Expand All @@ -39,8 +38,9 @@ func SignMessage(privateKey string, message string) (string, error) {

// Sign
var sigBytes []byte
if sigBytes, err = bsvec.SignCompact(bsvec.S256(), ecdsaPrivateKey, messageHash, true); err != nil {
if sigBytes, err = bsvec.SignCompact(bsvec.S256(), ecdsaPrivateKey, messageHash, false); err != nil {
return "", err
}

return base64.StdEncoding.EncodeToString(sigBytes), nil
}
30 changes: 18 additions & 12 deletions sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,46 @@ func TestSignMessage(t *testing.T) {
expectedSignature string
expectedError bool
}{
{
"0499f8239bfe10eb0f5e53d543635a423c96529dd85fa4bad42049a0b435ebdd",
"testing",
"G1ecUtmqAoM5QjwHh9p/V8VA/IwRRLds+pCXgrDZFuZDRugxQhDEo0L/dPscfTJk0v9T+DxFkc69H1OLwzqGyS4=",
false,
},
{
"ef0b8bad0be285099534277fde328f8f19b3be9cadcd4c08e6ac0b5f863745ac",
"This is a test message",
"H+zZagsyz7ioC/ZOa5EwsaKice0vs2BvZ0ljgkFHxD3vGsMlGeD4sXHEcfbI4h8lP29VitSBdf4A+nHXih7svf4=",
"G+zZagsyz7ioC/ZOa5EwsaKice0vs2BvZ0ljgkFHxD3vGsMlGeD4sXHEcfbI4h8lP29VitSBdf4A+nHXih7svf4=",
false,
},
{
"ef0b8bad0be285099534277fde328f8f19b3be9cadcd4c08e6ac0b5f863745ac",
"0499f8239bfe10eb0f5e53d543635a423c96529dd85fa4bad42049a0b435ebdd",
"This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af.",
"IFTYA0Vd/fBSl8XwgTDNcQ6LxIl6+Pz7wrOgNs1qyr/zb7R7FZvdISLHp6/TlHvUYqFzWvGbX1WvHPvrYXPkVx8=",
"GxRcFXQc7LHxFNpK5lzhR+LF5ixIvhB089bxYzTAV02yGHm/3ALxltz/W4lGp77Q5UTxdj+TU+96mdAcJ5b/fGs=",
false,
},
{
"93596babb564cbbdc84f2370c710b9bcc94333495b60af719b5fcf9ba00ba82c",
"This is a test message",
"IIuDw09ffPgEDuxEw5yHVp1+mi4QpuhAwLyQdpMTfsHCOkMqTKXuP7dSNWMEJqZsiQ8eKMDRvf2wZ4e5bxcu4O0=",
"HIuDw09ffPgEDuxEw5yHVp1+mi4QpuhAwLyQdpMTfsHCOkMqTKXuP7dSNWMEJqZsiQ8eKMDRvf2wZ4e5bxcu4O0=",
false,
},
{
"50381cf8f52936faae4a05a073a03d688a9fa206d005e87a39da436c75476d78",
"This is a test message",
"ILBmbjCY2Z7eSXGXZoBI3x2ZRaYUYOGtEaDjXetaY+zNDtMOvagsOGEHnVT3f5kXlEbuvmPydHqLnyvZP3cDOWk=",
"HLBmbjCY2Z7eSXGXZoBI3x2ZRaYUYOGtEaDjXetaY+zNDtMOvagsOGEHnVT3f5kXlEbuvmPydHqLnyvZP3cDOWk=",
false,
},
{
"c7726663147afd1add392d129086e57c0b05aa66a6ded564433c04bd55741434",
"This is a test message",
"IOI207QUnTLr2Ll+s4kUxNgLgorkc/Z5Pc+XNvUBYLy2TxaU6oHEJ2TTJ1mZVrtUyHm6e315v1tIjeosW3Odfqw=",
"HOI207QUnTLr2Ll+s4kUxNgLgorkc/Z5Pc+XNvUBYLy2TxaU6oHEJ2TTJ1mZVrtUyHm6e315v1tIjeosW3Odfqw=",
false,
},
{
"c7726663147afd1add392d129086e57c0b05aa66a6ded564433c04bd55741434",
"1",
"IMcRFG1VNN9TDGXpCU+9CqKLNOuhwQiXI5hZpkTOuYHKBDOWayNuAABofYLqUHYTMiMf9mYFQ0sPgFJZz3F7ELQ=",
"HMcRFG1VNN9TDGXpCU+9CqKLNOuhwQiXI5hZpkTOuYHKBDOWayNuAABofYLqUHYTMiMf9mYFQ0sPgFJZz3F7ELQ=",
false,
},
{
Expand All @@ -73,19 +79,19 @@ func TestSignMessage(t *testing.T) {
{
"c7726663147afd1add392d129086e57c0b",
"This is a test message",
"H6N+iPf23i2YkLsNzF/yyeBm9eSYBoY/HFV1Md1F0ElWBXW5E5mkdRtgjoRuq0yNb1CCFNWWlkn2gZknFJNUFJ8=",
"G6N+iPf23i2YkLsNzF/yyeBm9eSYBoY/HFV1Md1F0ElWBXW5E5mkdRtgjoRuq0yNb1CCFNWWlkn2gZknFJNUFJ8=",
false,
},
}

// Run tests
for _, test := range tests {
for idx, test := range tests {
if signature, err := SignMessage(test.inputKey, test.inputMessage); err != nil && !test.expectedError {
t.Errorf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputMessage, err.Error())
t.Errorf("%d %s Failed: [%s] [%s] inputted and error not expected but got: %s", idx, t.Name(), test.inputKey, test.inputMessage, err.Error())
} else if err == nil && test.expectedError {
t.Errorf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputMessage)
t.Errorf("%d %s Failed: [%s] [%s] inputted and error was expected", idx, t.Name(), test.inputKey, test.inputMessage)
} else if signature != test.expectedSignature {
t.Errorf("%s Failed: [%s] [%s] inputted [%s] expected but got: %s", t.Name(), test.inputKey, test.inputMessage, test.expectedSignature, signature)
t.Errorf("%d %s Failed: [%s] [%s] inputted [%s] expected but got: %s", idx, t.Name(), test.inputKey, test.inputMessage, test.expectedSignature, signature)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestVerifyMessage(t *testing.T) {
false,
},
{
"",
"1LN5p7Eg9Zju1b4g4eFPTBMPoMZGCxzrET",
"IBDscOd/Ov4yrd/YXantqajSAnW4fudpfr2KQy5GNo9pZybF12uNaal4KI822UpQLS/UJD+UK2SnNMn6Z3E4na8=",
"Testing!",
true,
Expand Down

0 comments on commit 003f7f9

Please sign in to comment.