How cybercongress/cyber-ts works
Main Components
• SDK Core Module: This forms the heart of the library and includes public exports such as the “cyber” object, the “ClientFactory” for creating RPC clients, and message composition modules for different blockchain operations.
• Message Composition Modules: These are organized by domain (e.g., cosmos, cosmwasm, ibc, and cyber exchange). They provide helper methods (withTypeUrl or fromPartial) for creating structured messages.
• RPC Client and Signing Modules: Components such as “getSigningCyberClient” and the functions for creating offline or proto signers to handle wallet connections, signing transactions, and broadcasting them.
• Proto and Amino Converters: Modules that handle the conversion between protocol buffer definitions and Amino message types. These are essential for correctly formatting and processing blockchain messages.
• Code Generation and Build Tools: Scripts (such as “scripts/codegen.ts”) and configuration files that generate and bundle the SDK’s artifacts, ensuring consistent protocol definitions across the packages.
• Contracts (Gift & Passport): Although not the main focus (as they are examples or part of contract testing/definitions), these provide definitions for the blockchain smart contracts used within the ecosystem.
Relationships and Interactions
• The ClientFactory (SDK Core) creates RPC clients that act as an intermediary between the developer’s application and the blockchain network.
• Message Composer modules (split by module type) are used by the developer to create transaction payloads.
• The signing modules (using either Amino or Proto signers) are responsible for signing these transactions before broadcasting them via the RPC client.
• Proto definitions and conversion layers (found under packages/cyber-ts/proto and related src directories) are compiled during build/codegen and then consumed by the client and message composition modules.
• External integrations (wallets like Keplr or cosmos-kit) connect to the signing modules; these are depicted as external components interacting with the SDK rather than part of the core.
Architectural Patterns and Design Principles
• Modular Design/Separation of Concerns: Each major functional area (e.g., RPC interactions, message composition, signing) is encapsulated in its own module or package.
• Monorepo Structure: Managed via Lerna, enabling the organization of multiple packages (for instance, “cyber-ts”) and shared code (like protos and helper utilities).
• Extensibility: The design of message composers and client factories allows the SDK to be extended to support new blockchain modules or configuration options easily.
• Abstraction of Complexity: Developers use high-level functions to create and sign messages without a deep understanding of lower-level protobuf or Amino details.
• Provide a high-level overview and also detail certain “lower-level” connections (like how the proto definitions from packages/cyber-ts/proto feed into the Registry and AminoTypes construction in the advanced usage).
• Components are clearly separated while showing the data flow and dependency chain from initialization (client creation) to message construction and transaction broadcasting.