Skip to content

Implement Key Management and Storage for Stacks Blockchain Provider #319

@CyrusVorwald

Description

@CyrusVorwald

We need to develop secure key management and storage capabilities for the Stacks blockchain provider. This includes implementing methods for creating, restoring, and importing keystores, as well as handling encryption and decryption of keystore data using our KMS.

Implement RestoreKeystore()

This method should:

  • Read the encrypted keystore file from the appropriate path
  • Decrypt the keystore data using the KMS
  • Read and decrypt the associated password file
  • Use the decrypted data to create a Stacks wallet object
  • Set the wallet object in the provider

func (p *Provider) RestoreKeystore(ctx context.Context) error

Implement NewKeystore()

This method should:

  • Generate a new Stacks private key
  • Create a keystore file with the generated key
  • Encrypt the keystore file and password using the KMS
  • Save the encrypted keystore and password files
  • Return the address associated with the new keystore

func (p *Provider) NewKeystore(password string) (string, error)

Implement ImportKeystore()

This method should:

  • Read the keystore file from the provided path
  • Decrypt the keystore using the provided passphrase
  • Encrypt the keystore and passphrase using the KMS
  • Save the encrypted keystore and passphrase files
  • Return the address associated with the imported keystore

func (p *Provider) ImportKeystore(ctx context.Context, keyPath, passphrase string) (string, error)

Implement keystorePath()

This method should return the appropriate file path for storing keystore files.

func (p *Provider) keystorePath(addr string) string

Implement Init() in the Stacks provider.go

func (p *Provider) Init(ctx context.Context, homeDir string, kms kms.KMS) error {
    p.kms = kms
    return nil
}

Acceptance Criteria

  • All keystore-related methods (RestoreKeystore, NewKeystore, ImportKeystore) are implemented and working correctly for Stacks
  • Keystore files are properly encrypted when saved and decrypted when read
  • The KMS is correctly utilized for encrypting and decrypting sensitive data
  • Unit tests cover all methods and edge cases with >80% code coverage

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions