|
1 | 1 | # Auth vs. Wallet vs. Signer: A Comparison |
2 | 2 |
|
3 | | -This document aims to provide an overview and comparison of `Auth`, `Wallet`, and `Signer`, three types commonly used for encryption and signing purposes in different networks. Each type serves a specific purpose and has its own characteristics and functionalities. |
| 3 | +This document provides an overview and comparison of `Auth`, `Wallet`, and `Signer`, three core abstractions used for cryptographic operations and transaction signing in the InterchainJS ecosystem. Each serves a specific purpose in the signing workflow and has distinct characteristics and functionalities. |
4 | 4 |
|
5 | 5 | ```mermaid |
6 | 6 | graph LR |
7 | | - subgraph AuthType[Auth] |
8 | | - ByteAuth --> |privateKey| PrivateKey |
9 | | - PrivateKey --> |sign| SignedTx |
10 | | - OfflineSigner[Hide PrivateKey] --> DocAuth |
11 | | - DocAuth --> |signDoc| SignedTx |
| 7 | + subgraph AuthLayer[Auth Layer] |
| 8 | + IWallet --> |getAccounts| IAccount[Account] |
| 9 | + IWallet --> |signByIndex| Signature |
| 10 | + OfflineSigner --> |signDirect/signAmino| SignedDoc |
12 | 11 | end |
13 | 12 |
|
14 | | - Wallet --> |accounts| IAccount[Account] |
15 | | - Wallet --> |toOfflineSigner| OfflineSigner |
16 | | -
|
17 | | - Signer --> |prefix| Prefix |
18 | | - Signer --> |account| Account |
19 | | - Signer --> |encoders| Encoder |
20 | | - Signer --> |signAndBroadCast| SignAndBroadCast |
| 13 | + subgraph SignerLayer[Signer Layer] |
| 14 | + IUniSigner --> |getAccounts| AccountData |
| 15 | + IUniSigner --> |sign| ISigned |
| 16 | + IUniSigner --> |signAndBroadcast| BroadcastResponse |
| 17 | + IUniSigner --> |signArbitrary| ICryptoBytes |
| 18 | + end |
21 | 19 |
|
22 | | - Account --> |auth| Auth |
| 20 | + AuthLayer --> SignerLayer |
| 21 | + IAccount --> |address/publicKey| SignerLayer |
23 | 22 |
|
24 | 23 | ``` |
25 | 24 |
|
26 | | -## 1. Auth |
| 25 | +## 1. Auth Layer |
| 26 | + |
| 27 | +The Auth layer provides the foundational cryptographic capabilities for account management and signing operations. It consists of two main abstractions: |
| 28 | + |
| 29 | +### IWallet Interface |
| 30 | + |
| 31 | +`IWallet` is the primary interface for managing cryptographic accounts and performing low-level signing operations: |
| 32 | + |
| 33 | +- **Account Management**: Provides access to multiple accounts through `getAccounts()` and `getAccountByIndex()` |
| 34 | +- **Direct Signing**: Offers `signByIndex()` method to sign arbitrary binary data using a specific account |
| 35 | +- **Network Agnostic**: Designed to work across different blockchain networks with configurable address derivation strategies |
| 36 | + |
| 37 | +### OfflineSigner Interface |
| 38 | + |
| 39 | +`OfflineSigner` provides a secure way to sign transactions without exposing private keys: |
| 40 | + |
| 41 | +- **External Wallet Integration**: Designed for integration with external wallets like Keplr, Leap, or hardware wallets |
| 42 | +- **Document Signing**: Supports both Direct (protobuf) and Amino (JSON) signing modes through `OfflineDirectSigner` and `OfflineAminoSigner` |
| 43 | +- **Privacy Preservation**: Keeps private keys secure within the external wallet while providing signing capabilities |
| 44 | + |
| 45 | +## 2. Wallet Implementations |
| 46 | + |
| 47 | +Wallet implementations provide concrete realizations of the `IWallet` interface, offering HD (Hierarchical Deterministic) key derivation and network-specific address generation: |
| 48 | + |
| 49 | +### Secp256k1HDWallet |
| 50 | + |
| 51 | +The primary wallet implementation for secp256k1 cryptography: |
| 52 | + |
| 53 | +- **HD Key Derivation**: Supports BIP-32/BIP-44 hierarchical deterministic key derivation from mnemonic phrases |
| 54 | +- **Multi-Account Support**: Can manage multiple accounts with different derivation paths |
| 55 | +- **Network Compatibility**: Works across Cosmos, Ethereum, and Injective networks with appropriate address strategies |
| 56 | +- **Offline Signer Conversion**: Can be converted to `OfflineDirectSigner` or `OfflineAminoSigner` for external wallet compatibility |
27 | 57 |
|
28 | | -`Auth` is a common implementation of an encryption algorithm that can be utilized across different networks. It provides a signing method to sign binary data. The primary features and characteristics of `Auth` are as follows: |
| 58 | +### Network-Specific Variants |
29 | 59 |
|
30 | | -- **Encryption Algorithm**: `Auth` implements an encryption algorithm that is compatible and usable across various networks. |
| 60 | +- **Cosmos**: `Secp256k1HDWallet` with bech32 address encoding |
| 61 | +- **Ethereum**: `Secp256k1HDWallet` with keccak256 hashing and hex address format |
| 62 | +- **Injective**: `EthSecp256k1HDWallet` with Ethereum-style addresses but Cosmos transaction format |
31 | 63 |
|
32 | | -- **Signing Binary Data**: `Auth` offers a method to sign binary data, which can be used for verifying the integrity and authenticity of the data. |
| 64 | +## 3. Signer Layer |
33 | 65 |
|
34 | | -- **Network Agnostic**: Auth is designed to work with different networks, making it a versatile solution for encryption and signing needs. |
| 66 | +The Signer layer provides the highest-level abstraction for transaction signing and broadcasting, implementing the `IUniSigner` interface. Signers can be constructed from either `IWallet` implementations or `OfflineSigner` interfaces. |
35 | 67 |
|
36 | | -## 2. Wallet |
| 68 | +### IUniSigner Interface |
37 | 69 |
|
38 | | -`Wallet` is a wrapper built upon `Auth`, providing additional functionalities and convenience, particularly for Web3 usage. `Wallet` extends the capabilities of `Auth` and introduces the following aspects: |
| 70 | +The universal signer interface provides a consistent API across all blockchain networks: |
39 | 71 |
|
40 | | -- **Signing Network and Document**: In addition to signing binary data, `Wallet` provides a signing method specifically designed for signing network-related information and sign mode specified documents. |
| 72 | +- **Account Management**: `getAccounts()` returns account information including addresses and public keys |
| 73 | +- **Transaction Workflow**: `sign()` creates signed transactions, `broadcast()` submits them to the network, and `signAndBroadcast()` combines both operations |
| 74 | +- **Arbitrary Signing**: `signArbitrary()` signs raw binary data for authentication purposes |
| 75 | +- **Network Abstraction**: Generic type parameters allow network-specific customization while maintaining a unified interface |
41 | 76 |
|
42 | | -- **Web3 Integration**: `Wallet` is tailored for Web3 usage, making it compatible with blockchain and decentralized applications. |
| 77 | +### Network-Specific Implementations |
43 | 78 |
|
44 | | -- **Enhanced Functionality**: `Wallet` encompasses the features of `Auth` while incorporating additional functionalities to facilitate secure interactions with Web3 wallets. |
| 79 | +- **Cosmos Signers**: `DirectSigner` and `AminoSigner` for protobuf and JSON signing modes |
| 80 | +- **Ethereum Signers**: `LegacySigner` and `Eip1559Signer` for different transaction types |
| 81 | +- **Injective Signers**: Cosmos-compatible signers with Ethereum-style address derivation |
45 | 82 |
|
46 | | -## 3. Signer |
| 83 | +### Construction Patterns |
47 | 84 |
|
48 | | -`Signer` is a class that can be constructed from `Auth` or `Wallet`. It focuses on providing a signing method specifically for directly signing human-readable messages. Key aspects of `Signer` include: |
| 85 | +Signers can be constructed in multiple ways: |
49 | 86 |
|
50 | | -- **Signing Human-Readable Messages**: `Signer` offers a dedicated signing method for signing messages that are in a human-readable format, such as plain text or structured data. |
| 87 | +1. **From IWallet**: Direct construction with full private key access |
| 88 | +2. **From OfflineSigner**: Construction for external wallet integration |
| 89 | +3. **Configuration-based**: Using network-specific configuration objects |
51 | 90 |
|
52 | | -- **Flexible Construction**: `Signer` can be constructed using either `Auth` or `Wallet`, allowing users to choose their preferred underlying implementation based on their specific requirements. |
| 91 | +## Summary |
53 | 92 |
|
54 | | -- **Message-Level Security**: `Signer` emphasizes the signing of human-readable messages, making it suitable for use cases where secure communication and message integrity are essential. |
| 93 | +The three-layer architecture provides clear separation of concerns: |
55 | 94 |
|
56 | | -In summary, `Auth` serves as a fundamental implementation of an encryption algorithm, providing a signing method for binary data. `Wallet`, built upon `Auth`, extends its capabilities by introducing network and document-specific signing methods, tailored for Web3 usage. `Signer`, the top-level layer, contains the code for structured data signing and focuses on dedicated methods for directly signing human-readable messages, which offers flexibility and message-level security. |
| 95 | +- **Auth Layer**: Foundational cryptographic operations and account management |
| 96 | +- **Wallet Layer**: HD key derivation and network-specific address generation |
| 97 | +- **Signer Layer**: High-level transaction signing and broadcasting with network abstraction |
57 | 98 |
|
58 | | -The hierarchical relationship between `Auth`, `Wallet`, and `Signer` positions Auth as the foundation, Wallet as the middle layer, and Signer as the top layer with the highest-level functionality for structured data signing. However, the specific choice among `Auth`, `Wallet`, or `Signer` depends on specific requirements and use cases, ensuring the appropriate level of encryption, signing, and security for various network-related operations. |
| 99 | +This design allows developers to choose the appropriate abstraction level based on their security requirements, from low-level cryptographic control to high-level transaction management, while maintaining compatibility across different blockchain networks. |
0 commit comments