Common Types

The common_types crate provides shared types, utilities, and protocol definitions used across all NCN Network components.


Overview

┌─────────────────────────────────────────────────────────────────────────────┐
│                            common_types Crate                                │
│                                                                             │
│   ┌───────────────────────────────────────────────────────────────────┐     │
│   │                    Protocol Buffer Types                           │     │
│   │   Generated from proto/common_types.proto                          │     │
│   │   • InferenceRequest, InferenceResponse                            │     │
│   │   • NodeInfo, ModelData, PaymentTree                               │     │
│   │   • PreprocessingValidation, CompletionValidation                  │     │
│   │   • SubnetMetadata, ValidatorSignature                             │     │
│   └───────────────────────────────────────────────────────────────────┘     │
│                                                                             │
│   ┌───────────────────────────────────────────────────────────────────┐     │
│   │                    Cryptographic Utilities                         │     │
│   │   • compute_message_hash() - SHA-256 hashing                       │     │
│   │   • sign_message() - secp256k1 ECDSA signing                       │     │
│   │   • verify_signature() - Signature verification                    │     │
│   │   • recover_signer() - Address recovery                            │     │
│   └───────────────────────────────────────────────────────────────────┘     │
│                                                                             │
│   ┌───────────────────────────────────────────────────────────────────┐     │
│   │                    Payment Utilities                               │     │
│   │   • PaymentTree calculations                                       │     │
│   │   • Fee estimation                                                 │     │
│   │   • Wei/ETH conversions                                            │     │
│   └───────────────────────────────────────────────────────────────────┘     │
│                                                                             │
│   ┌───────────────────────────────────────────────────────────────────┐     │
│   │                    Type Conversions                                │     │
│   │   • Protobuf ↔ Native type conversions                             │     │
│   │   • Serialization/deserialization                                  │     │
│   └───────────────────────────────────────────────────────────────────┘     │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Crate Structure


Usage

Add Dependency

Import Types


Protobuf Types

Core Types

Payment Types

Node Types


Cryptographic Utilities

Message Hashing

Signing

Verification

Preprocessing Message

Completion Message


Payment Utilities

Calculate Payment Tree

Total Payment

Wei/ETH Conversion


gRPC Services

GatewayClientService Stub

P2PRegistryService Stub


Building

Build Protobuf

The build.rs script automatically generates Rust code from proto/common_types.proto.

Regenerate Types


Dependencies


Last updated