Skip to content

Commit

Permalink
feat!: replace aggregator mnemonic with private key (#201)
Browse files Browse the repository at this point in the history
* feat: replace aggregator mnemonic with private key

Signed-off-by: Theo Butler <theodusbutler@gmail.com>

* refactor: Remove deprecated key_derive_path

Signed-off-by: Alexis Asseman <alexis@semiotic.ai>

---------

Signed-off-by: Theo Butler <theodusbutler@gmail.com>
Signed-off-by: Alexis Asseman <alexis@semiotic.ai>
Co-authored-by: Alexis Asseman <alexis@semiotic.ai>
  • Loading branch information
Theodus and aasseman committed Jan 2, 2024
1 parent bd6c82e commit 24583b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
12 changes: 6 additions & 6 deletions tap_aggregator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ A stateless JSON-RPC service that lets clients request an aggregate receipt from
A JSON-RPC service for the Timeline Aggregation Protocol that lets clients request an aggregate receipt from a list of
individual receipts.
Usage: tap_aggregator [OPTIONS] --mnemonic <MNEMONIC>
Usage: tap_aggregator [OPTIONS] --private-key <PRIVATE_KEY>
Options:
--port <PORT>
Port to listen on for JSON-RPC requests [env: TAP_PORT=] [default: 8080]
--mnemonic <MNEMONIC>
Sender mnemonic to be used to sign Receipt Aggregate Vouchers [env: TAP_MNEMONIC=]
--private-key <PRIVATE_KEY>
Sender private key for signing Receipt Aggregate Vouchers, as a hex string [env: TAP_PRIVATE_KEY=]
--max-request-body-size <MAX_REQUEST_BODY_SIZE>
Maximum request body size in bytes. Defaults to 10MB [env: TAP_MAX_REQUEST_BODY_SIZE=] [default: 10485760]
--max-response-body-size <MAX_RESPONSE_BODY_SIZE>
Expand Down Expand Up @@ -98,7 +98,7 @@ Warning object format (similar to the standard JSON-RPC error object):
We define these warning codes:

- `-32051` API version deprecation

Also returns an object containing the method's supported versions in the `data` field. Example:

```json
Expand Down Expand Up @@ -134,7 +134,7 @@ If the call fails, the error response format is as described in
In addition to the official spec, we define a few special errors:

- `-32001` Invalid API version.

Also returns an object containing the method's supported versions in the `data` field. Example:

```json
Expand All @@ -158,7 +158,7 @@ In addition to the official spec, we define a few special errors:
```

- `-32002` Aggregation error.

The aggregation function returned an error. Example:

```json
Expand Down
10 changes: 5 additions & 5 deletions tap_aggregator/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ mod tests {

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use ethers_signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
use ethers_signers::{LocalWallet, Signer};
use rstest::*;

use crate::aggregator;
use tap_core::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt};

#[fixture]
fn keys() -> (LocalWallet, Address) {
let wallet: LocalWallet = MnemonicBuilder::<English>::default()
.phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about")
.build()
.unwrap();
let wallet = LocalWallet::from_str(
"1ab42cc412b618bdea3a599e3c9bae199ebf030895b039e9db1e30dafb12b727",
)
.unwrap();
let address: [u8; 20] = wallet.address().into();
(wallet, address.into())
}
Expand Down
18 changes: 6 additions & 12 deletions tap_aggregator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#![doc = include_str!("../README.md")]

use std::borrow::Cow;
use std::str::FromStr;

use alloy_primitives::{Address, FixedBytes, U256};
use alloy_sol_types::Eip712Domain;
use anyhow::Result;
use clap::Parser;
use ethers_signers::{coins_bip39::English, MnemonicBuilder, Signer};
use ethers_signers::{LocalWallet, Signer};
use tokio::signal::unix::{signal, SignalKind};

use log::{debug, info};
Expand All @@ -24,13 +25,9 @@ struct Args {
#[arg(long, default_value_t = 8080, env = "TAP_PORT")]
port: u16,

/// Sender mnemonic to be used to generate key for signing Receipt Aggregate Vouchers.
#[arg(long, env = "TAP_MNEMONIC")]
mnemonic: String,

/// Sender key derive path to be used to generate key for signing Receipt Aggregate Vouchers.
#[arg(long, default_value = "m/44'/60'/0'/0/0", env = "TAP_KEY_DERIVE_PATH")]
key_derive_path: String,
/// Sender private key for signing Receipt Aggregate Vouchers, as a hex string.
#[arg(long, env = "TAP_PRIVATE_KEY")]
private_key: String,

/// Maximum request body size in bytes.
/// Defaults to 10MB.
Expand Down Expand Up @@ -90,10 +87,7 @@ async fn main() -> Result<()> {
tokio::spawn(metrics::run_server(args.metrics_port));

// Create a wallet from the mnemonic.
let wallet = MnemonicBuilder::<English>::default()
.phrase(args.mnemonic.as_str())
.derivation_path(&args.key_derive_path)?
.build()?;
let wallet = LocalWallet::from_str(&args.private_key)?;

info!("Wallet address: {:#40x}", wallet.address());

Expand Down

0 comments on commit 24583b4

Please sign in to comment.