Skip to content

Commit 87caa18

Browse files
make ED25519PrivateKeyValue public, add a way to instantiate ed25519Signer from it (#213)
* make ED25519PrivateKeyValue public * add a way to build a signer from the key value * Update pkg/keys/ed25519.go Co-authored-by: Ethan Lowman <[email protected]> Co-authored-by: Ethan Lowman <[email protected]>
1 parent b1554f8 commit 87caa18

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pkg/keys/ed25519.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (e *ed25519Verifier) UnmarshalPublicKey(key *data.PublicKey) error {
5454
return nil
5555
}
5656

57-
type ed25519PrivateKeyValue struct {
57+
type Ed25519PrivateKeyValue struct {
5858
Public data.HexBytes `json:"public"`
5959
Private data.HexBytes `json:"private"`
6060
}
@@ -83,12 +83,21 @@ func GenerateEd25519Key() (*ed25519Signer, error) {
8383
}, nil
8484
}
8585

86+
func NewEd25519Signer(keyValue Ed25519PrivateKeyValue) *ed25519Signer {
87+
return &ed25519Signer{
88+
PrivateKey: ed25519.PrivateKey(data.HexBytes(keyValue.Private)),
89+
keyType: data.KeyTypeEd25519,
90+
keyScheme: data.KeySchemeEd25519,
91+
keyAlgorithms: data.HashAlgorithms,
92+
}
93+
}
94+
8695
func (e *ed25519Signer) SignMessage(message []byte) ([]byte, error) {
8796
return e.Sign(rand.Reader, message, crypto.Hash(0))
8897
}
8998

9099
func (e *ed25519Signer) MarshalPrivateKey() (*data.PrivateKey, error) {
91-
valueBytes, err := json.Marshal(ed25519PrivateKeyValue{
100+
valueBytes, err := json.Marshal(Ed25519PrivateKeyValue{
92101
Public: data.HexBytes([]byte(e.PrivateKey.Public().(ed25519.PublicKey))),
93102
Private: data.HexBytes(e.PrivateKey),
94103
})
@@ -104,7 +113,7 @@ func (e *ed25519Signer) MarshalPrivateKey() (*data.PrivateKey, error) {
104113
}
105114

106115
func (e *ed25519Signer) UnmarshalPrivateKey(key *data.PrivateKey) error {
107-
keyValue := &ed25519PrivateKeyValue{}
116+
keyValue := &Ed25519PrivateKeyValue{}
108117
if err := json.Unmarshal(key.Value, keyValue); err != nil {
109118
return err
110119
}

0 commit comments

Comments
 (0)