Skip to content

Commit

Permalink
use compressed keyts
Browse files Browse the repository at this point in the history
  • Loading branch information
David Case committed Sep 11, 2024
1 parent 431d717 commit 9602749
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions aip.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Sign(privateKey *ec.PrivateKey, algorithm Algorithm, message string) (a *Ai
a = &Aip{Algorithm: algorithm, Data: prependedData}

// Sign using the private key and the message
if sig, err := bsm.SignMessageWithCompression(privateKey, []byte(strings.Join(prependedData, "")), false); err != nil {
if sig, err := bsm.SignMessage(privateKey, []byte(strings.Join(prependedData, ""))); err != nil {
return nil, err
} else {
a.Signature = base64.StdEncoding.EncodeToString(sig)
Expand All @@ -108,7 +108,7 @@ func Sign(privateKey *ec.PrivateKey, algorithm Algorithm, message string) (a *Ai
case BitcoinECDSA, BitcoinSignedMessage:
// Signing component = bitcoin address
// Get the address of the private key
if add, err := script.NewAddressFromPublicKeyWithCompression(privateKey.PubKey(), true, false); err != nil {
if add, err := script.NewAddressFromPublicKey(privateKey.PubKey(), true); err != nil {
return nil, err
} else {
a.AlgorithmSigningComponent = add.AddressString
Expand All @@ -119,7 +119,7 @@ func Sign(privateKey *ec.PrivateKey, algorithm Algorithm, message string) (a *Ai
// if pubkey, err := bitcoin.PubKeyFromPrivateKeyString(privateKey, false); err != nil {
// return
// }
a.AlgorithmSigningComponent = hex.EncodeToString(privateKey.PubKey().SerializeUncompressed())
a.AlgorithmSigningComponent = hex.EncodeToString(privateKey.PubKey().SerializeCompressed())
}

return
Expand Down
30 changes: 15 additions & 15 deletions aip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,71 +36,71 @@ func TestSign(t *testing.T) {
"0499f8239bfe10eb0f5e53d543635a423c96529dd85fa4bad42049a0b435ebdd",
BitcoinECDSA,
exampleMessage,
"HOpsJCCkmIOBs8HJIn3Od7aa/SLycQSsZ5QuLvaSlKobYvxpkE5Lcb4fAFLXp1h5pJTEHtm/SZICybovE8AcpiM=",
"IOpsJCCkmIOBs8HJIn3Od7aa/SLycQSsZ5QuLvaSlKobYvxpkE5Lcb4fAFLXp1h5pJTEHtm/SZICybovE8AcpiM=",
false,
false,
},
{
"80699541455b59a8a8a33b85892319de8b8e8944eb8b48e9467137825ae192e59f01",
Paymail,
exampleMessage,
"GwJif5FKr6rPpKYghZ7F7Rmaw00q5nWo6NiJOuje+6WBOM6qd8MlVnbWr2mrrA+aaDatHxavR8JTckpSfx1RJ1o=",
"HwJif5FKr6rPpKYghZ7F7Rmaw00q5nWo6NiJOuje+6WBOM6qd8MlVnbWr2mrrA+aaDatHxavR8JTckpSfx1RJ1o=",
false,
false,
},
{
"80699541455b59a8a8a33b85892319de8b8e8944eb8b48e9467137825ae192e59f01",
BitcoinECDSA,
"",
"G0ttfuC/XKY60ZRFmb12lARUJUekPJ1nD/f0WvJ94bJxT5U3SFHgHaJvAo1r/tVe1E0pMX+IuUxfOWckXdIS7wI=",
"H0ttfuC/XKY60ZRFmb12lARUJUekPJ1nD/f0WvJ94bJxT5U3SFHgHaJvAo1r/tVe1E0pMX+IuUxfOWckXdIS7wI=",
false,
false,
},
{
"e83385af76b2b1997326b567461fb73dd9c27eab9e1e86d26779f4650c5f2b75",
BitcoinECDSA,
exampleMessage,
"G2m+m3KyHeoWcJF7Sj09bzF+td7QjVw+baFJJ3VCTG4qfaMGXtx8roWprfXi5qP7NihY5lkfWCKCngnodWmG104=",
"H2m+m3KyHeoWcJF7Sj09bzF+td7QjVw+baFJJ3VCTG4qfaMGXtx8roWprfXi5qP7NihY5lkfWCKCngnodWmG104=",
false,
false,
},
{
"e83385af76b2b1997326b567461fb73dd9c27eab9e1e86d26779f4650c5f2b75",
BitcoinSignedMessage,
exampleMessage,
"G2m+m3KyHeoWcJF7Sj09bzF+td7QjVw+baFJJ3VCTG4qfaMGXtx8roWprfXi5qP7NihY5lkfWCKCngnodWmG104=",
"H2m+m3KyHeoWcJF7Sj09bzF+td7QjVw+baFJJ3VCTG4qfaMGXtx8roWprfXi5qP7NihY5lkfWCKCngnodWmG104=",
false,
false,
},
{
"e83385af76b2b1997326b567461fb73dd9c27eab9e1e86d26779f4650c5f2b75",
Paymail,
exampleMessage,
"G2m+m3KyHeoWcJF7Sj09bzF+td7QjVw+baFJJ3VCTG4qfaMGXtx8roWprfXi5qP7NihY5lkfWCKCngnodWmG104=",
"H2m+m3KyHeoWcJF7Sj09bzF+td7QjVw+baFJJ3VCTG4qfaMGXtx8roWprfXi5qP7NihY5lkfWCKCngnodWmG104=",
false,
false,
},
{
"73646673676572676164666764666761646667616466",
BitcoinECDSA,
exampleMessage,
"HIRS8UIWLYMwQUaiIDpe0ivhUqQVyHJg1kgOd/rviQJZWe2EFEI7PQblLaZofG+MjLCMbQLxzlV7DOAuFIdxNUc=",
"IIRS8UIWLYMwQUaiIDpe0ivhUqQVyHJg1kgOd/rviQJZWe2EFEI7PQblLaZofG+MjLCMbQLxzlV7DOAuFIdxNUc=",
false,
false,
},
{
"73646673676572676164666764666761646667616466",
BitcoinSignedMessage,
exampleMessage,
"HIRS8UIWLYMwQUaiIDpe0ivhUqQVyHJg1kgOd/rviQJZWe2EFEI7PQblLaZofG+MjLCMbQLxzlV7DOAuFIdxNUc=",
"IIRS8UIWLYMwQUaiIDpe0ivhUqQVyHJg1kgOd/rviQJZWe2EFEI7PQblLaZofG+MjLCMbQLxzlV7DOAuFIdxNUc=",
false,
false,
},
{
"73646673676572676164666764666761646667616466",
Paymail,
exampleMessage,
"HIRS8UIWLYMwQUaiIDpe0ivhUqQVyHJg1kgOd/rviQJZWe2EFEI7PQblLaZofG+MjLCMbQLxzlV7DOAuFIdxNUc=",
"IIRS8UIWLYMwQUaiIDpe0ivhUqQVyHJg1kgOd/rviQJZWe2EFEI7PQblLaZofG+MjLCMbQLxzlV7DOAuFIdxNUc=",
false,
false,
},
Expand Down Expand Up @@ -141,7 +141,7 @@ func ExampleSign() {
return
}
fmt.Printf("address: %s signature: %s", a.AlgorithmSigningComponent, a.Signature)
// Output:address: 1Dw6EeFNRZStXTUENRrV9tGUh1rT2hi6YP signature: HNQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=
// Output:address: 1DfGxKmgL3ETwUdNnXLBueEvNpjcDGcKgK signature: INQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=
}

// ExampleSign_paymail example using Sign()
Expand All @@ -152,7 +152,7 @@ func ExampleSign_paymail() {
return
}
fmt.Printf("address: %s signature: %s", a.AlgorithmSigningComponent, a.Signature)
// Output:address: 041b8c93100d35bd448f4646cc4678f278351b439b52b303ea31ec9edb5475e73f36e7ef720509250313fcf1b4c5af0dc7c5efa126efe2c3b7008e6f1487c61f31 signature: HNQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=
// Output:address: 031b8c93100d35bd448f4646cc4678f278351b439b52b303ea31ec9edb5475e73f signature: INQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=
}

// BenchmarkSign benchmarks the method Sign()
Expand Down Expand Up @@ -264,7 +264,7 @@ func ExampleAip_Validate() {
} else if err != nil {
fmt.Printf("signature validation failed: %s", err.Error())
}
// Output:valid signature: HNQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=
// Output:valid signature: INQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=
}

// BenchmarkAip_Validate benchmarks the method Validate()
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestSignOpReturnData(t *testing.T) {
"80699541455b59a8a8a33b85892319de8b8e8944eb8b48e9467137825ae192e59f01",
BitcoinECDSA,
[][]byte{[]byte(exampleMessage)},
"GwJif5FKr6rPpKYghZ7F7Rmaw00q5nWo6NiJOuje+6WBOM6qd8MlVnbWr2mrrA+aaDatHxavR8JTckpSfx1RJ1o=",
"HwJif5FKr6rPpKYghZ7F7Rmaw00q5nWo6NiJOuje+6WBOM6qd8MlVnbWr2mrrA+aaDatHxavR8JTckpSfx1RJ1o=",
"006a0c74657374206d65737361676522313550636948473232534e4c514a584d6f53556157566937575371633768436676610d424954434f494e5f45434453412131553151733836707847724e55796a37673752346d386b3879346b6d78766f756f4c5847774a696635464b72367250704b5967685a374637526d6177303071356e576f364e694a4f756a652b3657424f4d367164384d6c566e625772326d7272412b61614461744878617652384a54636b7053667831524a316f3d",
false,
false,
Expand All @@ -315,7 +315,7 @@ func TestSignOpReturnData(t *testing.T) {
"80699541455b59a8a8a33b85892319de8b8e8944eb8b48e9467137825ae192e59f01",
Paymail,
[][]byte{[]byte(exampleMessage)},
"GwJif5FKr6rPpKYghZ7F7Rmaw00q5nWo6NiJOuje+6WBOM6qd8MlVnbWr2mrrA+aaDatHxavR8JTckpSfx1RJ1o=",
"HwJif5FKr6rPpKYghZ7F7Rmaw00q5nWo6NiJOuje+6WBOM6qd8MlVnbWr2mrrA+aaDatHxavR8JTckpSfx1RJ1o=",
"006a0c74657374206d65737361676522313550636948473232534e4c514a584d6f5355615756693757537163376843667661077061796d61696c4c82303439393332396133303066333338653136343731373538313961666334356435353661366235666533633834313236663634633666353035616537616139333930343261346361633931326335396261663738323534346131626234356632333432613536303334343435656133313233643733393536663731306334333962654c5847774a696635464b72367250704b5967685a374637526d6177303071356e576f364e694a4f756a652b3657424f4d367164384d6c566e625772326d7272412b61614461744878617652384a54636b7053667831524a316f3d",
false,
false,
Expand Down Expand Up @@ -357,7 +357,7 @@ func ExampleSignOpReturnData() {
return
}
fmt.Printf("signature: %s outData: %x", a.Signature, outData)
// Output:signature: G7zptA7IbNaa7PQlblH1v5ElaOj3Zo49oiUrDMqfWM4QFNdIKDnXMkxLU1YgrxODd8uFNU279utUCC4MGPp5pjM= outData: [736f6d65206f705f72657475726e2064617461 313550636948473232534e4c514a584d6f5355615756693757537163376843667661 424954434f494e5f4543445341 314477364565464e525a5374585455454e5272563974475568317254326869365950 47377a7074413749624e61613750516c626c48317635456c614f6a335a6f34396f695572444d7166574d3451464e64494b446e584d6b784c5531596772784f44643875464e553237397574554343344d47507035706a4d3d]
// Output:signature: H7zptA7IbNaa7PQlblH1v5ElaOj3Zo49oiUrDMqfWM4QFNdIKDnXMkxLU1YgrxODd8uFNU279utUCC4MGPp5pjM= outData: [736f6d65206f705f72657475726e2064617461 313550636948473232534e4c514a584d6f5355615756693757537163376843667661 424954434f494e5f4543445341 31446647784b6d674c3345547755644e6e584c42756545764e706a634447634b674b 48377a7074413749624e61613750516c626c48317635456c614f6a335a6f34396f695572444d7166574d3451464e64494b446e584d6b784c5531596772784f44643875464e553237397574554343344d47507035706a4d3d]
}

// BenchmarkSignOpReturnData benchmarks the method SignOpReturnData()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
toolchain go1.22.5

require (
github.com/bitcoin-sv/go-sdk v1.1.5
github.com/bitcoin-sv/go-sdk v1.1.7
github.com/bitcoinschema/go-bob v0.4.3
github.com/bitcoinschema/go-bpu v0.1.3

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/bitcoin-sv/go-sdk v1.1.5 h1:AO2l33F4Ql61qfW3lBSjHsAmKhkziNhGdeiiM6DkaEI=
github.com/bitcoin-sv/go-sdk v1.1.5/go.mod h1:NOAkJLbjqKOLuxJmb9ABG86ExTZp4HS8+iygiDIUps4=
github.com/bitcoin-sv/go-sdk v1.1.7 h1:JbtaYCGUsHM7HTelLKSJp1NuYiG/xSNOdexjJ6w577A=
github.com/bitcoin-sv/go-sdk v1.1.7/go.mod h1:NOAkJLbjqKOLuxJmb9ABG86ExTZp4HS8+iygiDIUps4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down

0 comments on commit 9602749

Please sign in to comment.