Skip to content

Commit

Permalink
Provide access to privateKey for non-secp256k1 signing
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
  • Loading branch information
peterbroadhurst committed Aug 1, 2024
1 parent 083a920 commit 1e4fa5d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/keystorev3/aes128ctr.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
6 changes: 3 additions & 3 deletions pkg/keystorev3/pbkdf2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -44,9 +44,9 @@ func (w *walletFilePbkdf2) decrypt(password []byte) (err error) {

derivedKey := pbkdf2.Key(password, w.Crypto.KDFParams.Salt, w.Crypto.KDFParams.C, w.Crypto.KDFParams.DKLen, sha256.New)

privateKey, err := w.Crypto.decryptCommon(derivedKey)
w.privateKey, err = w.Crypto.decryptCommon(derivedKey)
if err == nil {
w.keypair, err = secp256k1.NewSecp256k1KeyPair(privateKey)
w.keypair, err = secp256k1.NewSecp256k1KeyPair(w.privateKey)
}
return err

Expand Down
6 changes: 3 additions & 3 deletions pkg/keystorev3/scrypt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -98,9 +98,9 @@ func (w *walletFileScrypt) decrypt(password []byte) error {
if err != nil {
return fmt.Errorf("invalid scrypt keystore: %s", err)
}
privateKey, err := w.Crypto.decryptCommon(derivedKey)
w.privateKey, err = w.Crypto.decryptCommon(derivedKey)
if err == nil {
w.keypair, err = secp256k1.NewSecp256k1KeyPair(privateKey)
w.keypair, err = secp256k1.NewSecp256k1KeyPair(w.privateKey)
}
return err
}
10 changes: 8 additions & 2 deletions pkg/keystorev3/walletfile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -34,6 +34,7 @@ const (
)

type WalletFile interface {
PrivateKey() []byte
KeyPair() *secp256k1.KeyPair
JSON() []byte
}
Expand Down Expand Up @@ -80,7 +81,8 @@ type walletFileBase struct {
ID *fftypes.UUID `json:"id"`
Version int `json:"version"`

keypair *secp256k1.KeyPair
privateKey []byte
keypair *secp256k1.KeyPair
}

type walletFileCommon struct {
Expand All @@ -102,6 +104,10 @@ func (w *walletFileBase) KeyPair() *secp256k1.KeyPair {
return w.keypair
}

func (w *walletFileBase) PrivateKey() []byte {
return w.privateKey

Check warning on line 108 in pkg/keystorev3/walletfile.go

View check run for this annotation

Codecov / codecov/patch

pkg/keystorev3/walletfile.go#L107-L108

Added lines #L107 - L108 were not covered by tests
}

func (w *walletFilePbkdf2) JSON() []byte {
b, _ := json.Marshal(w)
return b
Expand Down

0 comments on commit 1e4fa5d

Please sign in to comment.