Skip to content

Commit

Permalink
feat: support specification of private key file to claimer
Browse files Browse the repository at this point in the history
  • Loading branch information
tuler committed Mar 14, 2024
1 parent 3c9e0e6 commit a7057b8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added verification to ensure CARTESI_BLOCKCHAIN_ID matches the id returned from the Ethereum node
- Added support for CARTESI_AUTH_PRIVATE_KEY
- Added support for CARTESI_AUTH_PRIVATE_KEY and CARTESI_AUTH_PRIVATE_KEY_FILE

## Changed

Expand Down
8 changes: 8 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ Overrides `CARTESI_AUTH_AWS_KMS_*`.

The node will use this private key to sign transactions.

Overrides `CARTESI_AUTH_PRIVATE_KEY_FILE`, `CARTESI_AUTH_MNEMONIC`, `CARTESI_AUTH_MNEMONIC_FILE` and `CARTESI_AUTH_AWS_KMS_*`.

* **Type:** `string`

## `CARTESI_AUTH_PRIVATE_KEY_FILE`

The node will use the private key contained in this file to sign transactions.

Overrides `CARTESI_AUTH_MNEMONIC`, `CARTESI_AUTH_MNEMONIC_FILE` and `CARTESI_AUTH_AWS_KMS_*`.

* **Type:** `string`
Expand Down
9 changes: 9 additions & 0 deletions internal/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ redact = true
description = """
The node will use this private key to sign transactions.
Overrides `CARTESI_AUTH_PRIVATE_KEY_FILE`, `CARTESI_AUTH_MNEMONIC`, `CARTESI_AUTH_MNEMONIC_FILE` and `CARTESI_AUTH_AWS_KMS_*`."""

[auth.CARTESI_AUTH_PRIVATE_KEY_FILE]
go-type = "string"
export = false
redact = true
description = """
The node will use the private key contained in this file to sign transactions.
Overrides `CARTESI_AUTH_MNEMONIC`, `CARTESI_AUTH_MNEMONIC_FILE` and `CARTESI_AUTH_AWS_KMS_*`."""

[auth.CARTESI_AUTH_AWS_KMS_KEY_ID]
Expand Down
5 changes: 5 additions & 0 deletions internal/config/get.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion offchain/authority-claimer/src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ impl TryFrom<AuthorityClaimerCLI> for AuthorityClaimerConfig {
#[derive(Debug, Parser)]
#[command(name = "tx_signing_config")]
pub(crate) struct TxSigningCLIConfig {
/// Signer private key, overrides `tx_signing_mnemonic` , `tx_signing_mnemonic_file` and `tx_signing_aws_kms_*`
/// Signer private key, overrides `tx_signing_private_key_file`, `tx_signing_mnemonic` , `tx_signing_mnemonic_file` and `tx_signing_aws_kms_*`
#[arg(long, env)]
tx_signing_private_key: Option<String>,

/// Signer private key file, overrides `tx_signing_mnemonic` , `tx_signing_mnemonic_file` and `tx_signing_aws_kms_*`
#[arg(long, env)]
tx_signing_private_key_file: Option<String>,

/// Signer mnemonic, overrides `tx_signing_mnemonic_file` and `tx_signing_aws_kms_*`
#[arg(long, env)]
tx_signing_mnemonic: Option<String>,
Expand Down Expand Up @@ -125,6 +129,14 @@ impl TryFrom<TxSigningCLIConfig> for TxSigningConfig {
Ok(TxSigningConfig::PrivateKey {
private_key: Redacted::new(private_key),
})
} else if let Some(path) = cli.tx_signing_private_key_file {
let private_key = fs::read_to_string(path.clone())
.context(MnemonicFileSnafu { path })?
.trim()
.to_string();
Ok(TxSigningConfig::PrivateKey {
private_key: Redacted::new(private_key),
})
} else if let Some(mnemonic) = cli.tx_signing_mnemonic {
Ok(TxSigningConfig::Mnemonic {
mnemonic: Redacted::new(mnemonic),
Expand Down

0 comments on commit a7057b8

Please sign in to comment.