Skip to content

Commit 822313e

Browse files
committed
docs: add new crates doc
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 0b0b59e commit 822313e

File tree

9 files changed

+69
-26
lines changed

9 files changed

+69
-26
lines changed

tap_core/src/rav_request.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
//! Request to Tap Aggregator
5+
46
use alloy::sol_types::SolStruct;
57
use tap_receipt::rav::AggregationError;
68

tap_core/src/receipt.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
3-
//
3+
4+
//! # Receipts states and checks
5+
//!
6+
//! Receipts are used as single transaction promise of payment. A payment sender
7+
//! creates a receipt and ECDSA signs it, then sends it to a payment receiver.
8+
//! The payment receiver would verify the received receipt and store it to be
9+
//! accumulated with other received receipts in the future.
10+
//!
11+
//! A list of checks are performed on the received receipts to ensure they are valid.
12+
//! The checks are performed when storing the receipt and when aggregating the receipts
13+
//! into a Receipt Aggregate Voucher (RAV).
14+
//!
15+
//! Each receipt is wrapped into a State Machine that can be in one of the following states:
16+
//! - `Checking`: The receipt is being checked.
17+
//! - `Failed`: The receipt has failed a check or validation.
18+
//! - `AwaitingReserve`: The receipt has passed all checks and is awaiting escrow reservation.
19+
//! - `Reserved`: The receipt has successfully reserved escrow.
20+
//!
21+
//!
22+
423
pub use ::tap_receipt::*;

tap_core/src/signed_message.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
//! # EIP712 message and signatures
5+
//!
6+
//! This module contains the `EIP712SignedMessage` struct which is used to sign and verify messages
7+
//! using EIP712 standard.
8+
//!
9+
//! # Example
10+
//! ```rust
11+
//! # use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
12+
//! # let domain_separator = Eip712Domain::default();
13+
//! use tap_eip712_message::EIP712SignedMessage;
14+
//! # let wallet = PrivateKeySigner::random();
15+
//! # let wallet_address = wallet.address();
16+
//! # let message = msg::Receipt::new(Address::from([0x11u8; 20]), 100).unwrap();
17+
//!
18+
//! let signed_message = EIP712SignedMessage::new(&domain_separator, message, &wallet).unwrap();
19+
//! let signer = signed_message.recover_signer(&domain_separator).unwrap();
20+
//!
21+
//! assert_eq!(signer, wallet_address);
22+
//! ```
23+
//!
24+
425
pub use ::tap_eip712_message::*;

tap_eip712_message/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! # EIP712 message and signature
4+
//! # EIP712 signed message
55
//!
6-
//! This module contains the `EIP712SignedMessage` struct which is used to sign and verify messages
6+
//! This crate contains the `EIP712SignedMessage` struct which is used to sign and verify messages
77
//! using EIP712 standard.
88
//!
99
//! # Example
@@ -30,6 +30,7 @@ use alloy::{
3030
};
3131
use serde::{Deserialize, Serialize};
3232

33+
/// Errors returned by creation of messages and verify signature
3334
#[derive(thiserror::Error, Debug)]
3435
pub enum Eip712Error {
3536
/// `alloy` wallet error
@@ -50,9 +51,11 @@ pub struct Eip712SignedMessage<M: SolStruct> {
5051
pub signature: Signature,
5152
}
5253

54+
/// Signature that can be used in a HashSet
5355
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
5456
pub struct SignatureBytes([u8; 65]);
5557

58+
/// Extension for Signature to return [SignatureBytes]
5659
pub trait SignatureBytesExt {
5760
fn get_signature_bytes(&self) -> SignatureBytes;
5861
}

tap_graph/src/lib.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::time::{SystemTime, UNIX_EPOCH};
4+
//! # The Graph TAP structs
5+
//!
6+
//! These structs are used for communication between The Graph systems.
7+
//!
58
69
mod rav;
710
mod receipt;
811

912
pub use rav::{ReceiptAggregateVoucher, SignedRav};
1013
pub use receipt::{Receipt, SignedReceipt};
11-
12-
#[derive(Debug, thiserror::Error)]
13-
pub enum Error {
14-
/// Error when Rust fails to get the current system time
15-
#[error("Failed to get current system time: {source_error_message} ")]
16-
InvalidSystemTime { source_error_message: String },
17-
}
18-
19-
fn get_current_timestamp_u64_ns() -> Result<u64, Error> {
20-
Ok(SystemTime::now()
21-
.duration_since(UNIX_EPOCH)
22-
.map_err(|err| Error::InvalidSystemTime {
23-
source_error_message: err.to_string(),
24-
})?
25-
.as_nanos() as u64)
26-
}

tap_graph/src/rav.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ use tap_receipt::{
5050

5151
use crate::{receipt::Receipt, SignedReceipt};
5252

53-
/// EIP712 signed message for ReceiptAggregateVoucher
53+
/// A Rav wrapped in an Eip712SignedMessage
5454
pub type SignedRav = Eip712SignedMessage<ReceiptAggregateVoucher>;
5555

5656
sol! {
57-
/// Holds information needed for promise of payment signed with ECDSA
57+
/// ReceiptAggregateVoucher struct sent to Arbitrum to redeem payments
5858
///
5959
/// We use camelCase for field names to match the Ethereum ABI encoding
6060
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]

tap_graph/src/receipt.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
//! The payment receiver would verify the received receipt and store it to be
99
//! accumulated with other received receipts in the future.
1010
11+
use std::time::{SystemTime, SystemTimeError, UNIX_EPOCH};
12+
1113
use alloy::{primitives::Address, sol};
1214
use rand::{thread_rng, Rng};
1315
use serde::{Deserialize, Serialize};
1416
use tap_eip712_message::Eip712SignedMessage;
1517
use tap_receipt::WithValueAndTimestamp;
1618

17-
/// A signed receipt message
19+
/// A Receipt wrapped in an Eip712SignedMessage
1820
pub type SignedReceipt = Eip712SignedMessage<Receipt>;
1921

2022
sol! {
21-
/// Holds information needed for promise of payment signed with ECDSA
23+
/// Receipt struct used to pay for an off-chain service
2224
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
2325
struct Receipt {
2426
/// Unique allocation id this receipt belongs to
@@ -32,10 +34,14 @@ sol! {
3234
}
3335
}
3436

37+
fn get_current_timestamp_u64_ns() -> Result<u64, SystemTimeError> {
38+
Ok(SystemTime::now().duration_since(UNIX_EPOCH)?.as_nanos() as u64)
39+
}
40+
3541
impl Receipt {
3642
/// Returns a receipt with provided values
37-
pub fn new(allocation_id: Address, value: u128) -> Result<Self, crate::Error> {
38-
let timestamp_ns = crate::get_current_timestamp_u64_ns()?;
43+
pub fn new(allocation_id: Address, value: u128) -> Result<Self, SystemTimeError> {
44+
let timestamp_ns = get_current_timestamp_u64_ns()?;
3945
let nonce = thread_rng().gen::<u64>();
4046
Ok(Self {
4147
allocation_id,

tap_receipt/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ use tap_eip712_message::{Eip712SignedMessage, SignatureBytes, SignatureBytesExt}
3333
/// Result type for receipt
3434
pub type ReceiptResult<T> = Result<T, ReceiptError>;
3535

36+
/// Extra information for [checks::Check]
3637
pub type Context = anymap3::Map<dyn std::any::Any + Send + Sync>;
3738

39+
/// Extension that allows TAP Aggregation for any SolStruct receipt
3840
pub trait WithValueAndTimestamp {
3941
fn value(&self) -> u128;
4042
fn timestamp_ns(&self) -> u64;
4143
}
4244

45+
/// Extension that allows UniqueCheck for any SolStruct receipt
4346
pub trait WithUniqueId {
4447
type Output: Eq + std::hash::Hash;
4548
fn unique_id(&self) -> Self::Output;

tap_receipt/src/rav.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
//! Aggregation of Receipts
5+
46
use alloy::sol_types::SolStruct;
57
use tap_eip712_message::Eip712SignedMessage;
68

0 commit comments

Comments
 (0)