Skip to content

Commit

Permalink
fix(crypto): private key from string
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Aug 21, 2024
1 parent 1d3bf28 commit 01bc7db
Showing 1 changed file with 26 additions and 59 deletions.
85 changes: 26 additions & 59 deletions crypto/ed25519/private_key_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ed25519_test

import (
"encoding/hex"
"fmt"
"strings"
"testing"
Expand Down Expand Up @@ -60,10 +61,13 @@ func TestPrivateKeyFromString(t *testing.T) {
},
{
"",
"SECRET1RSW0NCUTJDFMWMSEYQVMXLW9ZP3WT2920S24XT55R6YKHL2G3ZG74C39" +
"GHXVZRY4F7F9ZZ5VJNWFYWSSN4MCFSSCP34DKY0ML0EF26SQ3J5575",
"SECRET1RJ6STNTA7Y3P2QLQF8A6QCX05F2H5TFNE5RSH066KZME4WVFXKE7QW097LG",
true,
[]byte{},
[]byte{
0x96, 0xa0, 0xb9, 0xaf, 0xbe, 0x24, 0x42, 0xa0, 0x7c, 0x9, 0x3f, 0x74, 0xc, 0x19, 0xf4,
0x4a, 0xaf, 0x45, 0xa6, 0x79, 0xa0, 0xe1, 0x77, 0xeb, 0x56, 0x16, 0xf3, 0x57, 0x31, 0x26,
0xb6, 0x7c,
},
},
}

Expand All @@ -79,60 +83,23 @@ func TestPrivateKeyFromString(t *testing.T) {
}
}

// // TestKeyGen ensures the KeyGen function works as intended.
// func TestKeyGen(t *testing.T) {
// tests := []struct {
// ikm string
// sk string
// }{
// {
// "",
// "Err",
// },
// {
// "00000000000000000000000000000000000000000000000000000000000000",
// "Err",
// },
// {
// "0000000000000000000000000000000000000000000000000000000000000000",
// "4d129a19df86a0f5345bad4cc6f249ec2a819ccc3386895beb4f7d98b3db6235",
// },
// {
// "2b1eb88002e83a622792d0b96d4f0695e328f49fdd32480ec0cf39c2c76463af",
// "0000f678e80740072a4a7fe8c7344db88a00ccc7db36aa51fa51f9c68e561584",
// },
// // The test vectors from EIP-2333
// // https://github.com/ethereum/EIPs/blob/784107449bd83a9327b54f82aba96de28d72b89a/EIPS/eip-2333.md#test-cases
// {
// "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e5349553" +
// "1f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04",
// "0d7359d57963ab8fbbde1852dcf553fedbc31f464d80ee7d40ae683122b45070",
// },
// {
// "3141592653589793238462643383279502884197169399375105820974944592",
// "41c9e07822b092a93fd6797396338c3ada4170cc81829fdfce6b5d34bd5e7ec7",
// },
// {
// "0099FF991111002299DD7744EE3355BBDD8844115566CC55663355668888CC00",
// "3cfa341ab3910a7d00d933d8f7c4fe87c91798a0397421d6b19fd5b815132e80",
// },
// {
// "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
// "2a0e28ffa5fbbe2f8e7aad4ed94f745d6bf755c51182e119bb1694fe61d3afca",
// },
// }
// TestKeyGen ensures the KeyGen function works as intended.
func TestKeyGen(t *testing.T) {
tests := []struct {
seed []byte
sk string
}{}

// for i, test := range tests {
// ikm, _ := hex.DecodeString(test.ikm)
// prv, err := bls.KeyGen(ikm, nil)
// if test.sk == "Err" {
// assert.Error(t, err,
// "test '%v' failed. no error", i)
// } else {
// assert.NoError(t, err,
// "test'%v' failed. has error", i)
// assert.Equal(t, test.sk, hex.EncodeToString(prv.Bytes()),
// "test '%v' failed. not equal", i)
// }
// }
// }
for i, test := range tests {
prv, err := ed25519.KeyGen(test.seed)
if test.sk == "Err" {
assert.Error(t, err,
"test '%v' failed. no error", i)
} else {
assert.NoError(t, err,
"test'%v' failed. has error", i)
assert.Equal(t, test.sk, hex.EncodeToString(prv.Bytes()),
"test '%v' failed. not equal", i)
}
}
}

0 comments on commit 01bc7db

Please sign in to comment.