Skip to content

Commit bcc05f3

Browse files
committed
docs: internal modules
1 parent 49646ea commit bcc05f3

File tree

4 files changed

+258
-0
lines changed

4 files changed

+258
-0
lines changed

docs/modules.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Radix dApp Toolkit internal modules
2+
3+
```mermaid
4+
flowchart TD
5+
%% Main Entry
6+
M[dApp toolkit modules]
7+
8+
%% Core Modules with Implementation Files
9+
M ---> WR[Wallet Request]
10+
M ---> S[Storage]
11+
M ---> E[Environment]
12+
M ---> CB[Connect Button]
13+
M ---> G[Gateway]
14+
M ---> ST[State]
15+
16+
%% Wallet Request Components
17+
WR ---> WRC1[data-request]
18+
WR ---> WRC2[pre-authorization-request]
19+
WR ---> WRC3[session]
20+
WR ---> WRC4[identity]
21+
WR ---> WRC5[encryption]
22+
WR ---> WRC7[Transport]
23+
WR ---> WRC8[request-resolver]
24+
WR ---> WRC9[request-items]
25+
26+
%% Transport Submodules
27+
WRC7 ---> T1[radix-connect-relay]
28+
WRC7 ---> T2[connector-extension]
29+
30+
%% Style Definitions
31+
classDef mainModule fill:#282a36,stroke:#ff79c6,stroke-width:2px,color:#f8f8f2,font-family:Monaco,font-weight:bold,font-size:14px;
32+
classDef implementation fill:#44475a,stroke:#8be9fd,stroke-width:1px,color:#50fa7b,font-family:Monaco,font-size:12px;
33+
classDef space fill:none,stroke:none;
34+
35+
%% Class Assignments
36+
class WR,S,E,CB,G,ST mainModule;
37+
class WRC1,WRC2,WRC3,WRC4,WRC5,WRC7,WRC8,WRC9 implementation;
38+
class T1,T2,T3 implementation;
39+
40+
%% Link Styling
41+
linkStyle default stroke:#bd93f9,stroke-width:2px;
42+
```
43+
44+
### Wallet Request
45+
46+
The central module for handling all wallet-related interactions. It coordinates communication between the dApp and the Radix Wallet through various submodules:
47+
48+
- **data-request**: Manages data requests to and from the wallet
49+
- **pre-authorization-request**: Handles wallet pre-authorization requests
50+
- **session**: Manages wallet connection sessions
51+
- **identity**: Handles user identity in context of wallet sessions
52+
- **encryption**: Provides encryption services for secure communication
53+
- **transport**: Manages different transport layers for wallet communication
54+
- **request-resolver**: Matches outgoing requests to incoming responses
55+
- **request-items**: Internal record of all requests
56+
57+
#### Transport Layer
58+
59+
The transport module supports multiple communication channels:
60+
61+
- **radix-connect-relay**: Handles communication through deep link and the Radix Connect relay service
62+
- **connector-extension**: Manages browser extension-based connections
63+
64+
### Storage
65+
66+
Manages persistent data storage for the dApp, handling:
67+
68+
- Wallet connection states
69+
- Session information
70+
- Cache management
71+
72+
### Environment
73+
74+
Handles environment-specific configuration and detection:
75+
76+
- Platform-specific features
77+
- Runtime configuration
78+
- Environment-specific optimizations
79+
80+
### Connect Button
81+
82+
Provides the UI component for wallet connection:
83+
84+
- User interface for wallet connection
85+
- Connection state management
86+
- Visual feedback for connection states
87+
- Customizable styling and behavior
88+
89+
### Gateway
90+
91+
Manages communication with the Radix Gateway:
92+
93+
- API endpoint management
94+
- Transaction status polling
95+
96+
### State
97+
98+
Manages the global state of the dApp toolkit:
99+
100+
- Connection state
101+
- Wallet state
102+
- Request states
103+
- Event management

docs/request-life-cycle.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Wallet request life-cycle
2+
3+
```mermaid
4+
%%{init: { 'theme': 'dark' } }%%
5+
sequenceDiagram
6+
participant App as dApp
7+
participant WR as WalletRequestModule
8+
participant TR as Transport
9+
participant RR as RequestResolver
10+
participant W as Wallet
11+
participant S as State
12+
13+
Note over App,S: Wallet Request Lifecycle
14+
15+
App->>WR: sendRequest()
16+
17+
Note right of WR: Request Initialization
18+
WR->>WR: Create walletInteraction
19+
WR->>WR: Add request to requestItemModule
20+
WR->>TR: Send via appropriate transport
21+
22+
Note right of TR: Transport Layer
23+
TR->>W: Send request to wallet
24+
TR-->>RR: Mark request as sent
25+
TR->>RR: Register for response
26+
27+
Note right of W: Wallet Processing
28+
W->>W: Process request
29+
W-->>TR: Send response
30+
31+
Note right of RR: Response Resolution
32+
TR->>RR: Forward wallet response
33+
RR->>RR: Match request to response
34+
RR->>RR: Resolve request
35+
36+
alt Data Request
37+
RR->>S: Update wallet data
38+
RR->>WR: Return wallet data
39+
else Transaction Request
40+
RR->>RR: Poll transaction status
41+
RR->>WR: Return transaction result
42+
else Pre-authorization Request
43+
RR->>RR: Update request status
44+
RR->>WR: Return authorization result
45+
end
46+
47+
WR->>App: Return result
48+
49+
Note right of WR: Cleanup
50+
WR->>RR: Update request status
51+
WR->>WR: Update button status
52+
WR->>WR: Cleanup if oneTime request
53+
```

docs/transport-ce.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Connector extension transport
2+
3+
```mermaid
4+
%%{init: { 'theme': 'dark' } }%%
5+
sequenceDiagram
6+
participant App as WalletRequestModule
7+
participant CE as ConnectorExtensionModule
8+
participant Sub as JS Events
9+
participant Ext as Connector Extension
10+
participant W as Wallet
11+
12+
Note over App,W: Extension Transport Flow
13+
14+
App->>CE: sendWalletInteraction(interaction)
15+
16+
Note right of CE: Extension Status Check
17+
CE->>Sub: getExtensionStatus
18+
Sub->>Ext: dispatchEvent(extensionStatus)
19+
Ext-->>Sub: MessageLifeCycleExtensionStatusEvent
20+
Sub-->>CE: CE status
21+
22+
Note right of CE: Request Setup
23+
CE->>CE: wrapWalletInteraction()
24+
25+
Note right of CE: Send Request
26+
CE->>Sub: send wallet interaction
27+
Sub->>Ext: dispatchEvent(interaction)
28+
Ext->>W: Forward request to wallet
29+
30+
Note right of CE: Response Handling Setup
31+
par Response Listeners
32+
CE->>Sub: Listen for wallet response
33+
and
34+
CE->>Sub: Listen for lifecycle events
35+
and
36+
CE->>Sub: Listen for cancellation
37+
end
38+
39+
alt Successful Response
40+
W-->>Ext: Send response
41+
Ext-->>Sub: dispatchEvent(incomingMessage)
42+
Sub->>CE: handle wallet response
43+
CE-->>App: Return wallet response
44+
else Cancellation
45+
App->>CE: cancelRequest()
46+
CE->>Sub: Send cancel request
47+
Sub->>Ext: dispatchEvent(cancelRequest)
48+
Ext-->>Sub: requestCancelSuccess/Fail
49+
CE-->>App: Return cancellation result
50+
else Extension Missing
51+
CE->>CE: Timer expires
52+
CE-->>App: Return missingExtension error
53+
end
54+
55+
CE->>Sub: Unsubscribe all listeners
56+
```

docs/transport-rcr.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Radix Connect Relay Transport
2+
3+
```mermaid
4+
%%{init: { 'theme': 'dark' } }%%
5+
sequenceDiagram
6+
participant App as WalletRequestModule
7+
participant RCR as RadixConnectRelayModule
8+
participant IM as IdentityModule
9+
participant SM as SessionModule
10+
participant DL as DeepLinkModule
11+
participant API as Radix Connect Relay
12+
participant W as Wallet
13+
14+
Note over App,W: Mobile Flow with Radix Connect Relay
15+
16+
App->>RCR: sendToWallet(walletInteraction)
17+
18+
Note right of RCR: Session & Identity Setup
19+
RCR->>SM: get session
20+
RCR->>IM: get dApp identity
21+
22+
Note right of IM: Create Request Signature
23+
IM->>IM: create signature
24+
25+
Note right of RCR: Prepare Deep Link
26+
RCR->>RCR: base64urlEncode(walletInteraction)
27+
28+
Note right of RCR: Send to Wallet
29+
RCR->>DL: deep link to wallet
30+
31+
DL->>W: deep link to wallet with params
32+
33+
Note right of RCR: Response Polling
34+
loop Check Relay
35+
RCR->>API: getResponses(sessionId)
36+
API-->>RCR: WalletResponse[]
37+
38+
Note right of RCR: Decrypt Response
39+
RCR->>IM: calculateSharedSecret()
40+
RCR->>RCR: decryptWalletResponse()
41+
end
42+
43+
RCR-->>App: Return wallet response
44+
45+
Note over App,W: Response Processing Complete
46+
```

0 commit comments

Comments
 (0)