Skip to content

Commit 19054af

Browse files
docs: improve root README.md organization and clarity
- Remove outdated sections (react demo, package deletion, graph dependencies) - Enhance documentation structure and readability - Improve section headings and descriptions - Add detailed tables for environment variables - Restructure error handling and troubleshooting guides Co-Authored-By: [email protected] <[email protected]>
1 parent 873aacf commit 19054af

File tree

1 file changed

+125
-114
lines changed

1 file changed

+125
-114
lines changed

README.md

Lines changed: 125 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -98,35 +98,37 @@ If you're a tech-savvy user and wish to utilize only specific submodules that ou
9898

9999
# Contributing and developing to this SDK
100100

101-
## Prerequisite
101+
## Prerequisites
102102

103-
- node (v19.x or above)
104-
- rust (v1.70.00 or above)
105-
- [wasm-pack](https://github.com/rustwasm/wasm-pack)
103+
Before you begin, ensure you have the following installed:
106104

107-
## Recommended
105+
- Node.js v19.0.0 or later
106+
- Rust v1.70.0 or later
107+
- [wasm-pack](https://github.com/rustwasm/wasm-pack) for WebAssembly compilation
108108

109-
- NX Console: https://nx.dev/core-features/integrate-with-editors
109+
## Development Tools
110110

111-
# Quick Start
111+
Recommended for better development experience:
112+
- [NX Console](https://nx.dev/core-features/integrate-with-editors) - Visual Studio Code extension for NX workspace management
112113

113-
The following commands will help you start developing with this repository.
114+
# Quick Start
114115

115-
First, install the dependencies via yarn:
116+
To start developing with this repository:
116117

118+
1. Install dependencies:
117119
```
118120
yarn
119121
```
120122

121123
## Building
122124

123-
You can build the project with the following commands:
125+
Build the project using one of these commands:
124126

125127
```
126-
// for local development - It stripped away operations that don't matter for local dev
128+
// For local development (optimized, excludes production-only operations)
127129
yarn build:dev
128130
129-
// you should never need to use yarn build unless you want to test or publish it
131+
// For testing and publishing (full build with all operations)
130132
yarn build
131133
```
132134

@@ -148,21 +150,7 @@ yarn test:local
148150

149151
`nx generate @nx/js:library`
150152

151-
## Create a new react demo app using the Lit JS SDK
152-
153-
```sh
154-
yarn tools --create --react contracts-sdk --demo
155-
```
156153

157-
## Deleting a package or app
158-
159-
```
160-
// delete an app from ./app/<app-name>
161-
yarn delete:app <app-name>
162-
163-
// delete a package from ./packages/<package-name>
164-
yarn delete:package <package-name>
165-
```
166154

167155
## Building
168156

@@ -210,138 +198,154 @@ Having done this setup, this is what the development cycle looks like moving for
210198
2. Rebuild specific package
211199
3. Rebuild client application.
212200

213-
### Building changes to Rust source
214-
215-
If changes are made to `packages/wasm` see [here](./packages/wasm/README.md) for info on building from source.
216-
217-
## Publishing
201+
### Building Rust Components
218202

219-
You must have at least nodejs v18 to do this.
203+
For changes to WebAssembly components in `packages/wasm`, refer to the [WebAssembly build guide](./packages/wasm/README.md).
220204

221-
1. Install the latest packages with `yarn install`
205+
## Publishing New Versions
222206

223-
2. Run `yarn bump` to bump the version
207+
Prerequisites:
208+
- Node.js v18.0.0 or later
224209

225-
3. Build all the packages with `yarn build`
210+
Publishing steps:
211+
1. Update dependencies: `yarn install`
212+
2. Increment version: `yarn bump`
213+
3. Build packages: `yarn build`
214+
4. Run tests:
215+
- Unit tests: `yarn test:unit`
216+
- E2E tests: `yarn test:local`
217+
5. Generate documentation: `yarn gen:docs --push`
218+
6. Publish packages: `yarn publish:packages`
219+
7. Commit with message: "Published version X.X.X"
226220

227-
4. Run the unit tests with `yarn test:unit` & e2e node tests `yarn test:local` locally & ensure that they pass
221+
## Testing Guide
228222

229-
5. Update the docs with `yarn gen:docs --push`
223+
### Available Test Commands
230224

231-
6. Finally, publish with `yarn publish:packages`
225+
| Command | Description |
226+
|---------|-------------|
227+
| `yarn test:unit` | Run unit tests for all packages |
228+
| `yarn test:local` | Launch E2E tests with Cypress and serve React test app |
232229

233-
7. Commit these changes "Published version X.X.X"
234-
235-
## Testing
236-
237-
### Quick Start on E2E Testing
238-
239-
The following will serve the react testing app and launch the cypress e2e testing after
240-
241-
```sh
242-
yarn test:local
243-
```
244-
245-
### Unit Tests
246-
247-
```sh
248-
yarn test:unit
249-
```
230+
### Running Tests
231+
1. Unit Tests:
232+
```sh
233+
yarn test:unit
234+
```
250235

251-
## Testing with a Local Lit Node
236+
2. End-to-End Tests:
237+
```sh
238+
yarn test:local
239+
```
240+
This command:
241+
- Starts the React testing application
242+
- Launches Cypress test runner
243+
- Executes E2E test suites
252244

253-
First, deploy your Lit Node Contracts, since the correct addresses will be pulled from the `../lit-assets/blockchain/contracts/deployed-lit-node-contracts-temp.json` file.
245+
## Local Development with Lit Node
254246

255-
Set these two env vars:
247+
### Setup Local Environment
248+
1. Deploy Lit Node Contracts (addresses will be read from `../lit-assets/blockchain/contracts/deployed-lit-node-contracts-temp.json`)
256249

250+
2. Configure environment variables:
257251
```sh
252+
# Enable local node development
258253
export LIT_JS_SDK_LOCAL_NODE_DEV="true"
259-
export LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY="putAFundedPrivateKeyOnChronicleHere"
260-
```
261254

262-
Run:
255+
# Set funded wallet for Chronicle testnet
256+
export LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY="your-funded-private-key"
257+
```
263258

259+
3. Update and build contracts:
264260
```sh
261+
# Fetch and generate contract updates
265262
yarn update:contracts-sdk --fetch
266263
yarn update:contracts-sdk --gen
264+
265+
# Build all packages
267266
yarn build:packages
268267
```
269268

270-
To run manual tests:
271-
269+
4. Start local development server:
272270
```sh
273-
yarn nx run nodejs:serve
271+
yarn nx run nodejs:serve
274272
```
275273

276-
## ENV Vars
274+
## Environment Variables
277275

278-
- LIT_JS_SDK_GITHUB_ACCESS_TOKEN - a github access token to get the contract ABIs from a private repo
279-
- LIT_JS_SDK_LOCAL_NODE_DEV - set to true to use a local node
280-
- LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY - set to a funded wallet on Chronicle Testnet
276+
| Variable | Description | Usage |
277+
|----------|-------------|--------|
278+
| `LIT_JS_SDK_GITHUB_ACCESS_TOKEN` | GitHub access token | Required for accessing contract ABIs from private repository |
279+
| `LIT_JS_SDK_LOCAL_NODE_DEV` | Local node development flag | Set to `true` to use a local Lit node |
280+
| `LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY` | Funded wallet private key | Required for Chronicle Testnet transactions |
281281

282-
# Error Handling
282+
# Error Handling Guide
283283

284-
This SDK uses custom error classes derived from [@openagenda/verror](https://github.com/OpenAgenda/verror) to handle errors between packages and to the SDK consumers.
285-
Normal error handling is also supported as VError extends the native Error class, but using VError allows for better error composition and information propagation.
286-
You can check their documentation for the extra fields that are added to the error object and methods on how to handle them in a safe way.
284+
## Overview
285+
The SDK implements a robust error handling system using [@openagenda/verror](https://github.com/OpenAgenda/verror). This system provides:
286+
- Detailed error information with cause tracking
287+
- Error composition and chaining
288+
- Additional context through metadata
289+
- Compatibility with native JavaScript Error handling
287290

288-
## Example
291+
## Using Error Handling
289292

293+
### Basic Example
290294
```ts
291295
import { VError } from '@openagenda/verror';
292296
import { LitNodeClientBadConfigError } from '@lit-protocol/constants';
293297

294298
try {
299+
// Simulate an error condition
295300
const someNativeError = new Error('some native error');
296301

302+
// Throw a Lit-specific error with context
297303
throw new LitNodeClientBadConfigError(
298304
{
299305
cause: someNativeError,
300-
info: {
301-
foo: 'bar',
302-
},
303-
meta: {
304-
baz: 'qux',
305-
},
306+
info: { foo: 'bar' },
307+
meta: { baz: 'qux' },
306308
},
307309
'some useful message'
308310
);
309311
} catch (e) {
310-
console.log(e.name); // LitNodeClientBadConfigError
311-
console.log(e.message); // some useful message: some native error
312-
console.log(e.info); // { foo: 'bar' }
313-
console.log(e.baz); // qux
314-
// VError.cause(e) is someNativeError
315-
// VError.info(e) is { foo: 'bar' }
316-
// VError.meta(e) is { baz: 'qux', code: 'lit_node_client_bad_config_error', kind: 'Config' }
317-
// Verror.fullStack(e) is the full stack trace composed of the error chain including the causes
312+
// Access error details
313+
console.log(e.name); // LitNodeClientBadConfigError
314+
console.log(e.message); // some useful message: some native error
315+
console.log(e.info); // { foo: 'bar' }
316+
console.log(e.baz); // qux
317+
318+
// Additional error information
319+
// - VError.cause(e): Original error (someNativeError)
320+
// - VError.info(e): Additional context ({ foo: 'bar' })
321+
// - VError.meta(e): Metadata ({ baz: 'qux', code: 'lit_node_client_bad_config_error', kind: 'Config' })
322+
// - VError.fullStack(e): Complete error chain stack trace
318323
}
319324
```
320325

321-
## Creating a new error
322-
323-
In file `packages/constants/src/lib/errors.ts` you can find the list of errors that are currently supported and add new ones if needed.
326+
## Creating Custom Errors
324327

325-
To create and use a new error, you need to:
328+
To add new error types:
326329

327-
1. Add the error information to the `LIT_ERROR` object in `packages/constants/src/lib/errors.ts`
328-
2. Export the error from the `errors.ts` file at the end of the file
329-
3. Import the error where you need it
330-
4. Throw the error in your code adding all the information a user might need to know about the error such as the cause, the info, etc.
330+
1. Locate `packages/constants/src/lib/errors.ts`
331+
2. Add your error definition to the `LIT_ERROR` object
332+
3. Export the new error class
333+
4. Import and use in your code with relevant context:
334+
```ts
335+
throw new YourCustomError({
336+
cause: originalError,
337+
info: { /* context */ },
338+
meta: { /* metadata */ }
339+
}, "Error message");
340+
```
331341

332342
# Dockerfile
333343

334344
...coming soon
335345

336346
## Other Commands
337347

338-
### Interactive graph dependencies using NX
339348

340-
```
341-
yarn graph
342-
```
343-
344-
![](https://i.ibb.co/2dLyMTW/Screenshot-2022-11-15-at-15-18-46.png)
345349

346350
# Core Systems and Services
347351

@@ -365,37 +369,44 @@ Key components available across packages:
365369
- `generatePrivateKey()`: Key generation utilities
366370
- `TinnyEnvironment`: Testing environment setup
367371

368-
# FAQs & Common Errors
369-
370-
<details>
371-
<summary>(React) Failed to parse source map from</summary>
372+
# Troubleshooting Guide
372373

373-
In your React package.json, add `GENERATE_SOURCEMAP=false` to your start script
374+
## Common Issues and Solutions
374375

375-
eg.
376+
### React Source Map Error
377+
**Problem:** "Failed to parse source map from" error in React
376378

377-
```
379+
**Solution:**
380+
Disable source map generation in your React `package.json`:
381+
```json
382+
{
378383
"scripts": {
379384
"start": "GENERATE_SOURCEMAP=false react-scripts start",
380385
"build": "react-scripts build",
381386
"test": "react-scripts test",
382387
"eject": "react-scripts eject"
383-
},
388+
}
389+
}
384390
```
385391

386-
</details>
387-
388-
<details>
389-
<summary>Reference Error: crypto is not defined</summary>
392+
### Crypto API Error
393+
**Problem:** "Reference Error: crypto is not defined"
390394

395+
**Solution:**
396+
Add the following polyfill for environments without native crypto:
391397
```js
392398
import crypto, { createHash } from 'crypto';
399+
400+
// Add crypto to global scope
393401
Object.defineProperty(globalThis, 'crypto', {
394402
value: {
403+
// Implement getRandomValues
395404
getRandomValues: (arr: any) => crypto.randomBytes(arr.length),
405+
406+
// Implement subtle crypto
396407
subtle: {
397408
digest: (algorithm: string, data: Uint8Array) => {
398-
return new Promise((resolve, reject) =>
409+
return new Promise((resolve) =>
399410
resolve(
400411
createHash(algorithm.toLowerCase().replace('-', ''))
401412
.update(data)

0 commit comments

Comments
 (0)