Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8283b0c
Wip encryptor
connorwstein Oct 6, 2025
0875ec0
Add a test and more documentation for encryption
connorwstein Oct 6, 2025
232ceb6
Switch to protobuf to trim the ciphertext size
connorwstein Oct 6, 2025
7d07720
More test coverage
connorwstein Oct 6, 2025
b6404fa
add field to capability response metadata to convey the total number …
EasterTheBunny Oct 6, 2025
746a336
Comply with go naming conventions
connorwstein Oct 7, 2025
d78be60
Improve encrypt test coverage
connorwstein Oct 7, 2025
95ea1d7
Add a test harness, fix a few bugs
connorwstein Oct 7, 2025
6aabe3c
Merge branch 'main' into ARCH-331-keystore-encryptor-2
connorwstein Oct 7, 2025
a5c9b8f
Added a readme warning
connorwstein Oct 7, 2025
cd499e3
Merge branch 'ARCH-331-keystore-encryptor-2' of github.com:smartcontr…
connorwstein Oct 7, 2025
3bfb012
Comments and re-orient API around anonymous encryption
connorwstein Oct 8, 2025
f531344
Merge branch 'main' into ARCH-331-keystore-encryptor-2
connorwstein Oct 8, 2025
4068a44
Merge branch 'main' into ARCH-331-keystore-encryptor-2
connorwstein Oct 8, 2025
8d9d70f
Rename
connorwstein Oct 9, 2025
64c3c47
Merge branch 'main' into ARCH-331-keystore-encryptor-2
connorwstein Oct 9, 2025
ee722e1
PR comments + port a critical fix
connorwstein Oct 9, 2025
1906533
Merge branch 'ARCH-331-keystore-encryptor-2' of github.com:smartcontr…
connorwstein Oct 9, 2025
5096a99
Fix test
connorwstein Oct 9, 2025
2f72586
Use errors.New
connorwstein Oct 9, 2025
d46dc32
Merge branch 'main' into ARCH-331-keystore-encryptor-2
connorwstein Oct 10, 2025
ac08a79
Keystore signer impl (#1598)
connorwstein Oct 10, 2025
1082fd4
Merge branch 'main' into ARCH-331-keystore-encryptor-2
connorwstein Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions keystore/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
WARNING: In development do not use in production.

# Keystore
Design principles:
- Use structs for typed extensibility of the interfaces. Easy
Expand Down
24 changes: 20 additions & 4 deletions keystore/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keystore

import (
"context"
"crypto/ecdh"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rand"
Expand Down Expand Up @@ -128,6 +129,8 @@ func ValidKeyName(name string) error {
return nil
}

// CreateKeys creates multiple keys in a single operation. The response preserves the order of the request.
// It's atomic - either all keys are created or none are created.
func (ks *keystore) CreateKeys(ctx context.Context, req CreateKeysRequest) (CreateKeysResponse, error) {
ks.mu.Lock()
defer ks.mu.Unlock()
Expand All @@ -152,16 +155,19 @@ func (ks *keystore) CreateKeys(ctx context.Context, req CreateKeysRequest) (Crea
return CreateKeysResponse{}, fmt.Errorf("failed to get public key from private key: %w", err)
}
ksCopy[keyReq.KeyName] = newKey(keyReq.KeyType, internal.NewRaw(privateKey), publicKey, time.Now(), []byte{})
case EcdsaSecp256k1:
case ECDSA_S256:
privateKey, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
if err != nil {
return CreateKeysResponse{}, fmt.Errorf("failed to generate EcdsaSecp256k1 key: %w", err)
return CreateKeysResponse{}, fmt.Errorf("failed to generate ECDSA_S256 key: %w", err)
}
publicKey, err := publicKeyFromPrivateKey(internal.NewRaw(privateKey.D.Bytes()), keyReq.KeyType)
// Must copy the private key into 32 byte slice because leading zeros are stripped.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fuzzer caught this. Double checked the other key types and they are correct

privateKeyBytes := make([]byte, 32)
copy(privateKeyBytes, privateKey.D.Bytes())
publicKey, err := publicKeyFromPrivateKey(internal.NewRaw(privateKeyBytes), keyReq.KeyType)
if err != nil {
return CreateKeysResponse{}, fmt.Errorf("failed to get public key from private key: %w", err)
}
ksCopy[keyReq.KeyName] = newKey(keyReq.KeyType, internal.NewRaw(privateKey.D.Bytes()), publicKey, time.Now(), []byte{})
ksCopy[keyReq.KeyName] = newKey(keyReq.KeyType, internal.NewRaw(privateKeyBytes), publicKey, time.Now(), []byte{})
case X25519:
privateKey := [curve25519.ScalarSize]byte{}
_, err := rand.Read(privateKey[:])
Expand All @@ -173,6 +179,16 @@ func (ks *keystore) CreateKeys(ctx context.Context, req CreateKeysRequest) (Crea
return CreateKeysResponse{}, fmt.Errorf("failed to get public key from private key: %w", err)
}
ksCopy[keyReq.KeyName] = newKey(keyReq.KeyType, internal.NewRaw(privateKey[:]), publicKey, time.Now(), []byte{})
case ECDH_P256:
privateKey, err := ecdh.P256().GenerateKey(rand.Reader)
if err != nil {
return CreateKeysResponse{}, fmt.Errorf("failed to generate ECDH_P256 key: %w", err)
}
publicKey, err := publicKeyFromPrivateKey(internal.NewRaw(privateKey.Bytes()), keyReq.KeyType)
if err != nil {
return CreateKeysResponse{}, fmt.Errorf("failed to get public key from private key: %w", err)
}
ksCopy[keyReq.KeyName] = newKey(keyReq.KeyType, internal.NewRaw(privateKey.Bytes()), publicKey, time.Now(), []byte{})
default:
return CreateKeysResponse{}, fmt.Errorf("%w: %s", ErrUnsupportedKeyType, keyReq.KeyType)
}
Expand Down
5 changes: 2 additions & 3 deletions keystore/admin_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keystore_test

import (
"context"
"fmt"
"sort"
"sync"
Expand All @@ -14,7 +13,7 @@ import (
)

func TestKeystore_CreateDeleteReadKeys(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
type key struct {
name string
metadata []byte
Expand Down Expand Up @@ -161,7 +160,7 @@ func TestKeystore_CreateDeleteReadKeys(t *testing.T) {
func TestKeystore_ConcurrentCreateAndRead(t *testing.T) {
t.Parallel()

ctx := context.Background()
ctx := t.Context()
st := storage.NewMemoryStorage()
ks, err := keystore.LoadKeystore(ctx, st, keystore.EncryptionParams{
Password: "test",
Expand Down
Loading
Loading