2020-10-28 06:36:49 +01:00
|
|
|
package keys
|
2019-04-07 06:29:12 +02:00
|
|
|
|
|
|
|
import (
|
2020-10-28 06:36:49 +01:00
|
|
|
"encoding/hex"
|
2019-04-07 06:29:12 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gotest.tools/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// The purpose of this test, is to make sure the function converts btcec.PublicKey to DER format the same way
|
|
|
|
// lbry SDK does as this is the bytes that are put into protobuf and the same bytes are used for verify signatures.
|
|
|
|
// Making sure these
|
|
|
|
func TestPublicKeyToDER(t *testing.T) {
|
2020-10-28 06:36:49 +01:00
|
|
|
publicKeyHex := "3056301006072a8648ce3d020106052b8104000a03420004d015365a40f3e5c03c87227168e5851f44659837bcf6a3398ae633bc37d04ee19baeb26dc888003bd728146dbea39f5344bf8c52cedaf1a3a1623a0166f4a367"
|
|
|
|
pubKeyBytes, err := hex.DecodeString(publicKeyHex)
|
2019-04-07 06:29:12 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2020-10-28 06:36:49 +01:00
|
|
|
|
|
|
|
p1, err := GetPublicKeyFromBytes(pubKeyBytes)
|
2019-04-07 06:29:12 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
pubkeyBytes2, err := PublicKeyToDER(p1)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2020-10-28 06:36:49 +01:00
|
|
|
for i, b := range pubKeyBytes {
|
2019-04-07 06:29:12 +02:00
|
|
|
assert.Assert(t, b == pubkeyBytes2[i], "DER format in bytes must match!")
|
|
|
|
}
|
|
|
|
|
2020-10-28 06:36:49 +01:00
|
|
|
p2, err := GetPublicKeyFromBytes(pubkeyBytes2)
|
2019-04-07 06:29:12 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
assert.Assert(t, p1.IsEqual(p2), "The keys produced must be the same key!")
|
|
|
|
}
|