@@ -4,12 +4,12 @@ A reusable React wallet component for blockchain applications, designed to provi
44
55## Features
66
7- - 🔐 Multiple authentication providers (Password, Google, Github, etc.)
8- - 🔑 Session key management
9- - 💰 Transaction handling
10- - 📡 WebSocket integration for real-time updates
11- - 🎨 Customizable UI
12- - 🔄 State management via React Context
7+ - 🔐 Multiple authentication providers (Password, Google, Github, etc.)
8+ - 🔑 Session key management
9+ - 💰 Transaction handling
10+ - 📡 WebSocket integration for real-time updates
11+ - 🎨 Customizable UI
12+ - 🔄 State management via React Context
1313
1414## Installation
1515
@@ -20,12 +20,13 @@ yarn add hyli-wallet
2020```
2121
2222Required peer dependencies:
23+
2324``` json
2425{
25- "hyli-check-secret" : " ^0.3.2" ,
26- "react" : " ^19.1.0" ,
27- "react-dom" : " ^19.1.0" ,
28- "react-router-dom" : " ^7.5.0"
26+ "hyli-check-secret" : " ^0.3.2" ,
27+ "react" : " ^19.1.0" ,
28+ "react-dom" : " ^19.1.0" ,
29+ "react-router-dom" : " ^7.5.0"
2930}
3031```
3132
@@ -34,32 +35,34 @@ Required peer dependencies:
34351 . First, wrap your application with the ` WalletProvider ` :
3536
3637``` tsx
37- import { WalletProvider } from ' hyli-wallet' ;
38+ import { WalletProvider } from " hyli-wallet" ;
3839
3940function App() {
40- return (
41- <WalletProvider config = { {
42- nodeBaseUrl: ' NODE_BASE_URL' ,
43- walletServerBaseUrl: ' WALLET_SERVER_URL' ,
44- applicationWsUrl: ' WEBSOCKET_URL'
45- }} >
46- <YourApp />
47- </WalletProvider >
48- );
41+ return (
42+ <WalletProvider
43+ config = { {
44+ nodeBaseUrl: " NODE_BASE_URL" ,
45+ walletServerBaseUrl: " WALLET_SERVER_URL" ,
46+ applicationWsUrl: " WEBSOCKET_URL" ,
47+ }}
48+ >
49+ <YourApp />
50+ </WalletProvider >
51+ );
4952}
5053```
5154
52552 . Use the wallet component:
5356
5457``` tsx
55- import { HyliWallet } from ' hyli-wallet' ;
58+ import { HyliWallet } from " hyli-wallet" ;
5659
5760function YourComponent() {
58- return (
59- <HyliWallet
60- providers = { [' password' , ' google' , ' github' ]} // Optional: specify auth providers
61- />
62- );
61+ return (
62+ <HyliWallet
63+ providers = { [" password" , " google" , " github" ]} // Optional: specify auth providers
64+ />
65+ );
6366}
6467```
6568
@@ -68,39 +71,39 @@ function YourComponent() {
6871The ` useWallet ` hook provides access to wallet functionality:
6972
7073``` tsx
71- import { useWallet } from ' hyli-wallet' ;
74+ import { useWallet } from " hyli-wallet" ;
7275
7376function WalletFeatures() {
74- const {
75- wallet, // Current wallet state
76- isLoading,
77- error,
78- login, // Login function
79- registerAccount, // Create new account
80- logout, // Logout function
81- registerSessionKey, // Create new session key
82- removeSessionKey, // Remove existing session key
83- } = useWallet ();
84-
85- return (
86- <div >
87- { wallet ? (
77+ const {
78+ wallet, // Current wallet state
79+ isLoading,
80+ error,
81+ login, // Login function
82+ registerAccount, // Create new account
83+ logout, // Logout function
84+ registerSessionKey, // Create new session key
85+ removeSessionKey, // Remove existing session key
86+ } = useWallet ();
87+
88+ return (
8889 <div >
89- <p >Welcome, { wallet .username } </p >
90- <p >Balance: { balance } HYLLAR</p >
91- <button onClick = { logout } >Logout</button >
90+ { wallet ? (
91+ <div >
92+ <p >Welcome, { wallet .username } </p >
93+ <p >Balance: { balance } HYLLAR</p >
94+ <button onClick = { logout } >Logout</button >
95+ </div >
96+ ) : (
97+ <p >Please connect your wallet</p >
98+ )}
9299 </div >
93- ) : (
94- <p >Please connect your wallet</p >
95- )}
96- </div >
97- );
100+ );
98101}
99102```
100103
101104## Session Key Management
102105
103- > ** Note:**
106+ > ** Note:**
104107> You can find a complete and exhaustive implementation in [ ` here ` ] ( ../front/src/components/wallet/SessionKeys.tsx ) .
105108
106109### Creating a Session Key
@@ -143,8 +146,8 @@ Session keys allow for automated transaction signing:
143146Once you have a session key, you can use it to send transactions:
144147
145148``` typescript
146- import { useWallet } from ' hyli-wallet' ;
147- import { nodeService } from ' your-services' ;
149+ import { useWallet } from " hyli-wallet" ;
150+ import { nodeService } from " your-services" ;
148151
149152const { wallet, createIdentityBlobs } = useWallet ();
150153
@@ -153,30 +156,27 @@ const [blob0, blob1] = createIdentityBlobs();
153156
154157// Create and send the transaction
155158const blobTx = {
156- identity: wallet .address ,
157- blobs: [blob0 , blob1 ],
159+ identity: wallet .address ,
160+ blobs: [blob0 , blob1 ],
158161};
159162// blob0 is the secp256k1 blob containing the signature done with the wallet's session keu
160163// blob1 is the hyli-wallet contract that verifies that the session key is valid
161164
162165const txHash = await nodeService .client .sendBlobTx (blobTx );
163- console .log (' Transaction sent:' , txHash );
166+ console .log (" Transaction sent:" , txHash );
164167```
165168
166169### Removing a Session Key
167170
168171When a session key is no longer needed, you can remove it:
169172
170173``` typescript
171- import { useWallet } from ' hyli-wallet' ;
174+ import { useWallet } from " hyli-wallet" ;
172175
173176const { removeSessionKey } = useWallet ();
174177
175178// Remove the session key using the wallet password
176- await removeSessionKey (
177- ' your_password' ,
178- ' session_key_public_key'
179- );
179+ await removeSessionKey (" your_password" , " session_key_public_key" );
180180```
181181
182182## WebSocket Integration
@@ -185,12 +185,12 @@ Real-time updates for transactions and wallet events:
185185
186186``` tsx
187187function TransactionMonitor() {
188- useWebSocketConnection (wallet ?.address , event => {
189- if (event .tx .status === ' Success' ) {
190- // Handle successful transaction
191- fetchBalance ();
192- }
193- });
188+ useWebSocketConnection (wallet ?.address , ( event ) => {
189+ if (event .tx .status === " Success" ) {
190+ // Handle successful transaction
191+ fetchBalance ();
192+ }
193+ });
194194}
195195```
196196
@@ -199,15 +199,12 @@ function TransactionMonitor() {
199199You can customize the connect button by providing a render prop:
200200
201201``` tsx
202- <HyliWallet
203- button = { ({ onClick }) => (
204- <button
205- className = " custom-button"
206- onClick = { onClick }
207- >
208- Connect to Wallet
209- </button >
210- )}
202+ <HyliWallet
203+ button = { ({ onClick }) => (
204+ <button className = " custom-button" onClick = { onClick } >
205+ Connect to Wallet
206+ </button >
207+ )}
211208/>
212209```
213210
0 commit comments