Skip to content

Commit 6fb9791

Browse files
authored
Merge pull request #754 from LIT-Protocol/devin/1735845077-update-readmes
docs: improve package descriptions and standardize README formatting
2 parents 71a8f2d + 0801de0 commit 6fb9791

File tree

17 files changed

+569
-215
lines changed

17 files changed

+569
-215
lines changed

README.md

Lines changed: 158 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -98,35 +98,45 @@ 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
110+
111+
Recommended for better development experience:
112+
113+
- [NX Console](https://nx.dev/core-features/integrate-with-editors) - Visual Studio Code extension for NX workspace management
110114

111115
# Quick Start
112116

113-
The following commands will help you start developing with this repository.
117+
To start developing with this repository:
114118

115-
First, install the dependencies via yarn:
119+
1. Install dependencies:
116120

117121
```
118122
yarn
119123
```
120124

125+
2. Build the packages:
126+
127+
```
128+
yarn build:dev
129+
```
130+
121131
## Building
122132

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

125135
```
126-
// for local development - It stripped away operations that don't matter for local dev
136+
// For local development (optimized, excludes production-only operations)
127137
yarn build:dev
128138
129-
// you should never need to use yarn build unless you want to test or publish it
139+
// For testing and publishing (full build with all operations)
130140
yarn build
131141
```
132142

@@ -148,22 +158,6 @@ yarn test:local
148158

149159
`nx generate @nx/js:library`
150160

151-
## Create a new react demo app using the Lit JS SDK
152-
153-
```sh
154-
yarn tools --create --react contracts-sdk --demo
155-
```
156-
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-
```
166-
167161
## Building
168162

169163
```sh
@@ -210,170 +204,216 @@ Having done this setup, this is what the development cycle looks like moving for
210204
2. Rebuild specific package
211205
3. Rebuild client application.
212206

213-
### Building changes to Rust source
207+
### Building Rust Components
214208

215-
If changes are made to `packages/wasm` see [here](./packages/wasm/README.md) for info on building from source.
209+
For changes to WebAssembly components in `packages/wasm`, refer to the [WebAssembly build guide](./packages/wasm/README.md).
216210

217-
## Publishing
211+
## Publishing New Versions
218212

219-
You must have at least nodejs v18 to do this.
213+
Prerequisites:
220214

221-
1. Install the latest packages with `yarn install`
215+
- Node.js v18.0.0 or later
222216

223-
2. Run `yarn bump` to bump the version
217+
Publishing steps:
224218

225-
3. Build all the packages with `yarn build`
219+
1. Create a release PR:
226220

227-
4. Run the unit tests with `yarn test:unit` & e2e node tests `yarn test:local` locally & ensure that they pass
221+
- Create a new branch from master with format `vX.X.X-Publish`
222+
- Add changelog as PR description
223+
- Add "Release" label to the PR
224+
- Reference example: https://github.com/LIT-Protocol/js-sdk/pull/753
228225

229-
5. Update the docs with `yarn gen:docs --push`
226+
2. After PR approval, proceed with publishing:
227+
- Update dependencies: `yarn install`
228+
- Increment version: `yarn bump`
229+
- Build packages: `yarn build`
230+
- Run tests:
231+
- Unit tests: `yarn test:unit`
232+
- E2E tests: `yarn test:local`
233+
- Generate documentation: `yarn gen:docs --push`
234+
- Publish packages: `yarn publish:packages`
235+
- Commit with message: "Published version X.X.X"
230236

231-
6. Finally, publish with `yarn publish:packages`
237+
## Testing Guide
232238

233-
7. Commit these changes "Published version X.X.X"
239+
### Available Test Commands
234240

235-
## Testing
241+
| Command | Description |
242+
| ----------------- | ------------------------------------ |
243+
| `yarn test:unit` | Run unit tests for all packages |
244+
| `yarn test:local` | Run E2E tests in Node.js environment |
236245

237-
### Quick Start on E2E Testing
246+
### Running Tests
238247

239-
The following will serve the react testing app and launch the cypress e2e testing after
248+
1. Unit Tests:
240249

241-
```sh
242-
yarn test:local
243-
```
250+
```sh
251+
yarn test:unit
252+
```
244253

245-
### Unit Tests
254+
2. End-to-End Tests:
246255

247-
```sh
248-
yarn test:unit
249-
```
256+
```sh
257+
yarn test:local
258+
```
250259

251-
## Testing with a Local Lit Node
260+
Optional Environment Variables:
252261

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.
262+
- NETWORK=<network_name> (datil, datil-test, datil-dev, etc.)
263+
- DEBUG=true/false
254264

255-
Set these two env vars:
265+
Optional Flags:
256266

257-
```sh
258-
export LIT_JS_SDK_LOCAL_NODE_DEV="true"
259-
export LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY="putAFundedPrivateKeyOnChronicleHere"
260-
```
267+
- --filter=<test-name>
261268

262-
Run:
269+
See more in `local-tests/README.md`
263270

264-
```sh
265-
yarn update:contracts-sdk --fetch
266-
yarn update:contracts-sdk --gen
267-
yarn build:packages
268-
```
271+
## Local Development with Lit Node
272+
273+
### Setup Local Environment
274+
275+
1. Deploy Lit Node Contracts (addresses will be read from `../lit-assets/blockchain/contracts/deployed-lit-node-contracts-temp.json`)
269276

270-
To run manual tests:
277+
2. Configure environment variables:
271278

272279
```sh
273-
yarn nx run nodejs:serve
280+
# Enable local node development
281+
export LIT_JS_SDK_LOCAL_NODE_DEV="true"
282+
283+
# Set funded wallet for Chronicle testnet
284+
export LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY="your-funded-private-key"
274285
```
275286

276-
## ENV Vars
287+
## Environment Variables
288+
289+
| Variable | Description | Usage |
290+
| -------------------------------------- | --------------------------- | ------------------------------------------------------------ |
291+
| `LIT_JS_SDK_GITHUB_ACCESS_TOKEN` | GitHub access token | Required for accessing contract ABIs from private repository |
292+
| `LIT_JS_SDK_LOCAL_NODE_DEV` | Local node development flag | Set to `true` to use a local Lit node |
293+
| `LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY` | Funded wallet private key | Required for Chronicle Testnet transactions |
277294

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
295+
# Error Handling Guide
281296

282-
# Error Handling
297+
## Overview
283298

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.
299+
The SDK implements a robust error handling system using [@openagenda/verror](https://github.com/OpenAgenda/verror). This system provides:
287300

288-
## Example
301+
- Detailed error information with cause tracking
302+
- Error composition and chaining
303+
- Additional context through metadata
304+
- Compatibility with native JavaScript Error handling
305+
306+
## Using Error Handling
307+
308+
### Basic Example
289309

290310
```ts
291311
import { VError } from '@openagenda/verror';
292312
import { LitNodeClientBadConfigError } from '@lit-protocol/constants';
293313

294314
try {
315+
// Simulate an error condition
295316
const someNativeError = new Error('some native error');
296317

318+
// Throw a Lit-specific error with context
297319
throw new LitNodeClientBadConfigError(
298320
{
299321
cause: someNativeError,
300-
info: {
301-
foo: 'bar',
302-
},
303-
meta: {
304-
baz: 'qux',
305-
},
322+
info: { foo: 'bar' },
323+
meta: { baz: 'qux' },
306324
},
307325
'some useful message'
308326
);
309327
} catch (e) {
328+
// Access error details
310329
console.log(e.name); // LitNodeClientBadConfigError
311330
console.log(e.message); // some useful message: some native error
312331
console.log(e.info); // { foo: 'bar' }
313332
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
333+
334+
// Additional error information
335+
// - VError.cause(e): Original error (someNativeError)
336+
// - VError.info(e): Additional context ({ foo: 'bar' })
337+
// - VError.meta(e): Metadata ({ baz: 'qux', code: 'lit_node_client_bad_config_error', kind: 'Config' })
338+
// - VError.fullStack(e): Complete error chain stack trace
318339
}
319340
```
320341

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.
324-
325-
To create and use a new error, you need to:
326-
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.
342+
## Creating Custom Errors
343+
344+
To add new error types:
345+
346+
1. Locate `packages/constants/src/lib/errors.ts`
347+
2. Add your error definition to the `LIT_ERROR` object
348+
3. Export the new error class
349+
4. Import and use in your code with relevant context:
350+
```ts
351+
throw new YourCustomError(
352+
{
353+
cause: originalError,
354+
info: {
355+
/* context */
356+
},
357+
meta: {
358+
/* metadata */
359+
},
360+
},
361+
'Error message'
362+
);
363+
```
331364

332365
# Dockerfile
333366

334367
...coming soon
335368

336369
## Other Commands
337370

338-
### Interactive graph dependencies using NX
371+
# Core Systems and Services
339372

340-
```
341-
yarn graph
342-
```
373+
The Lit Protocol SDK provides the following core systems:
343374

344-
![](https://i.ibb.co/2dLyMTW/Screenshot-2022-11-15-at-15-18-46.png)
375+
- Cryptographic key management (PKP - Programmable Key Pair)
376+
- Blockchain wallet interactions (Ethereum, Solana, Cosmos)
377+
- Decentralized authentication and authorization
378+
- Distributed computing and signing
379+
- Smart contract management
380+
- Access control and encryption services
345381

346-
# FAQs & Common Errors
382+
# Main Functions and Classes
347383

348-
<details>
349-
<summary>(React) Failed to parse source map from</summary>
384+
Key components available across packages:
350385

351-
In your React package.json, add `GENERATE_SOURCEMAP=false` to your start script
386+
- `PKPEthersWallet`: Ethereum wallet management for PKP
387+
- `LitNodeClient`: Network interaction client
388+
- `executeJs()`: Decentralized JavaScript execution
389+
- `signMessageWithEncryptedKey()`: Cryptographic signing
390+
- `generatePrivateKey()`: Key generation utilities
391+
- `TinnyEnvironment`: Testing environment setup
352392

353-
eg.
393+
# Troubleshooting Guide
354394

355-
```
356-
"scripts": {
357-
"start": "GENERATE_SOURCEMAP=false react-scripts start",
358-
"build": "react-scripts build",
359-
"test": "react-scripts test",
360-
"eject": "react-scripts eject"
361-
},
362-
```
395+
## Common Issues and Solutions
396+
397+
### Crypto API Error
363398

364-
</details>
399+
**Problem:** "Reference Error: crypto is not defined"
365400

366-
<details>
367-
<summary>Reference Error: crypto is not defined</summary>
401+
**Solution:**
402+
Add the following polyfill for environments without native crypto:
368403

369404
```js
370405
import crypto, { createHash } from 'crypto';
406+
407+
// Add crypto to global scope
371408
Object.defineProperty(globalThis, 'crypto', {
372409
value: {
410+
// Implement getRandomValues
373411
getRandomValues: (arr: any) => crypto.randomBytes(arr.length),
412+
413+
// Implement subtle crypto
374414
subtle: {
375415
digest: (algorithm: string, data: Uint8Array) => {
376-
return new Promise((resolve, reject) =>
416+
return new Promise((resolve) =>
377417
resolve(
378418
createHash(algorithm.toLowerCase().replace('-', ''))
379419
.update(data)
@@ -386,10 +426,9 @@ Object.defineProperty(globalThis, 'crypto', {
386426
});
387427
```
388428

389-
</details>
390-
<details>
391-
<summary>error Command failed with exit code 13.</summary>
429+
### Unexpected Error on Node
392430

393-
Make sure your node version is above v18.0.0
431+
**Problem:** Exit code 13
394432

395-
</details>
433+
**Solution:**
434+
Make sure your node version is above v18.0.0

0 commit comments

Comments
 (0)