Skip to content

Commit

Permalink
feat: replace aggregator mnemonic with private key
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Jan 2, 2024
1 parent d841a44 commit 76dc74e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 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
12 changes: 6 additions & 6 deletions tap_aggregator/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub async fn check_and_aggregate_receipts(
check_receipt_timestamps(receipts, previous_rav.as_ref())?;

// Get the allocation id from the first receipt, return error if there are no receipts
let allocation_id = match receipts.get(0) {
let allocation_id = match receipts.first() {
Some(receipt) => receipt.message.allocation_id,
None => return Err(tap_core::Error::NoValidReceiptsForRAVRequest.into()),
};
Expand Down 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
14 changes: 6 additions & 8 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,9 +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 private key for signing Receipt Aggregate Vouchers, as a hex string.
#[arg(long, env = "TAP_PRIVATE_KEY")]
private_key: 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")]
Expand Down Expand Up @@ -90,10 +91,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 76dc74e

Please sign in to comment.