|
| 1 | +# Concepts |
| 2 | + |
| 3 | +The FastAuth Browser SDK is designed with a modular architecture that separates concerns between authentication, signing, and blockchain interactions. This section provides a high-level overview of the core components and their relationships. |
| 4 | + |
| 5 | +## Architecture Overview |
| 6 | + |
| 7 | +```mermaid |
| 8 | +graph TD |
| 9 | + Client["FastAuthClient<P>"] |
| 10 | + Provider["IFastAuthProvider"] |
| 11 | + Signer["FastAuthSigner<P>"] |
| 12 | + Connection["NEAR Connection"] |
| 13 | +
|
| 14 | + subgraph "Authentication Layer" |
| 15 | + Provider |
| 16 | + AuthProviders["Auth0Provider<br/>CustomProvider<br/>..."] |
| 17 | + end |
| 18 | +
|
| 19 | + subgraph "Application Layer" |
| 20 | + Client |
| 21 | + end |
| 22 | +
|
| 23 | + subgraph "Transaction Layer" |
| 24 | + Signer |
| 25 | + Actions["Transaction Actions<br/>Delegate Actions<br/>Account Creation"] |
| 26 | + end |
| 27 | +
|
| 28 | + subgraph "Blockchain Layer" |
| 29 | + Connection |
| 30 | + Contracts["MPC Contract<br/>FastAuth Contract"] |
| 31 | + end |
| 32 | +
|
| 33 | + Client -->|"uses"| Provider |
| 34 | + Client -->|"creates"| Signer |
| 35 | + Client -->|"uses"| Connection |
| 36 | + Signer -->|"uses"| Provider |
| 37 | + Signer -->|"uses"| Connection |
| 38 | +
|
| 39 | + Provider -.->|"implements"| AuthProviders |
| 40 | + Signer -->|"creates"| Actions |
| 41 | + Connection -->|"interacts with"| Contracts |
| 42 | +``` |
| 43 | + |
| 44 | +## Core Components |
| 45 | + |
| 46 | +### FastAuthClient |
| 47 | + |
| 48 | +The **FastAuthClient** is the main orchestrator and entry point for the SDK. It provides a unified interface for authentication and transaction operations. |
| 49 | + |
| 50 | +**Key Responsibilities:** |
| 51 | + |
| 52 | +- Manages the authentication lifecycle (login/logout) |
| 53 | +- Creates and configures signer instances |
| 54 | +- Abstracts provider-specific implementations |
| 55 | +- Enforces authentication requirements before transaction operations |
| 56 | + |
| 57 | +### FastAuthProvider |
| 58 | + |
| 59 | +The **FastAuthProvider** interface defines the contract for authentication providers. This abstraction allows the SDK to support multiple authentication backends. |
| 60 | + |
| 61 | +**Key Capabilities:** |
| 62 | + |
| 63 | +- Authentication state management (`isLoggedIn()`) |
| 64 | +- Login/logout operations |
| 65 | +- Transaction signature requests |
| 66 | +- Cryptographic path derivation |
| 67 | + |
| 68 | +**Provider Types:** |
| 69 | + |
| 70 | +- **Auth0Provider**: Integration with Auth0 authentication service |
| 71 | +- **CustomProvider**: Support for custom authentication backends |
| 72 | + |
| 73 | +### FastAuthSigner |
| 74 | + |
| 75 | +The **FastAuthSigner** handles all transaction-related operations and blockchain interactions. It bridges the authentication layer with NEAR blockchain functionality. |
| 76 | + |
| 77 | +**Key Features:** |
| 78 | + |
| 79 | +- Transaction signing and submission |
| 80 | +- Account creation operations |
| 81 | +- Delegate action handling |
| 82 | +- Public key derivation from MPC contracts |
| 83 | + |
| 84 | +**Transaction Types:** |
| 85 | + |
| 86 | +- Standard NEAR transactions |
| 87 | +- Delegate actions for gasless transactions |
| 88 | +- Account creation with public key registration |
| 89 | + |
| 90 | +### NEAR Connection |
| 91 | + |
| 92 | +The **NEAR Connection** (from `near-api-js`) provides the blockchain connectivity layer. |
| 93 | + |
| 94 | +**Responsibilities:** |
| 95 | + |
| 96 | +- Network communication with NEAR blockchain |
| 97 | +- Contract method calls and queries |
| 98 | +- Transaction broadcasting |
| 99 | +- Block and state queries |
| 100 | + |
| 101 | +## Component Interactions |
| 102 | + |
| 103 | +### Authentication Flow |
| 104 | + |
| 105 | +1. **Client** receives login request from application |
| 106 | +2. **Client** delegates to **Provider** for authentication |
| 107 | +3. **Provider** handles authentication mechanism (OAuth, custom, etc.) |
| 108 | +4. **Provider** maintains authentication state |
| 109 | + |
| 110 | +### Transaction Flow |
| 111 | + |
| 112 | +1. Application requests **Signer** from **Client** |
| 113 | +2. **Client** verifies authentication status via **Provider** |
| 114 | +3. **Client** creates and initializes **Signer** instance |
| 115 | +4. **Signer** uses **Provider** for signature requests |
| 116 | +5. **Signer** interacts with NEAR contracts via **Connection** |
| 117 | + |
| 118 | +### Key Benefits |
| 119 | + |
| 120 | +**Modularity**: Each component has a single responsibility, making the SDK maintainable and testable. |
| 121 | + |
| 122 | +**Extensibility**: The provider pattern allows easy integration of new authentication mechanisms. |
| 123 | + |
| 124 | +**Type Safety**: Generic types ensure compile-time validation across component interactions. |
| 125 | + |
| 126 | +**Separation of Concerns**: Authentication, signing, and blockchain interactions are cleanly separated. |
| 127 | + |
| 128 | +**Provider Abstraction**: Applications can switch authentication providers without changing business logic. |
| 129 | + |
| 130 | +## Integration Points |
| 131 | + |
| 132 | +### Smart Contracts |
| 133 | + |
| 134 | +- **MPC Contract**: Handles multi-party computation for key derivation |
| 135 | +- **FastAuth Contract**: Manages authentication and signature verification |
| 136 | + |
| 137 | +### External Services |
| 138 | + |
| 139 | +- **Authentication Providers**: Auth0, custom backends, identity providers |
| 140 | +- **NEAR Network**: Mainnet, testnet, or custom networks |
| 141 | +- **Browser APIs**: LocalStorage, SessionStorage for state persistence |
0 commit comments