@@ -98,35 +98,45 @@ If you're a tech-savvy user and wish to utilize only specific submodules that ou
98
98
99
99
# Contributing and developing to this SDK
100
100
101
- ## Prerequisite
101
+ ## Prerequisites
102
102
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:
106
104
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
108
108
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
110
114
111
115
# Quick Start
112
116
113
- The following commands will help you start developing with this repository.
117
+ To start developing with this repository:
114
118
115
- First, install the dependencies via yarn :
119
+ 1 . Install dependencies:
116
120
117
121
```
118
122
yarn
119
123
```
120
124
125
+ 2 . Build the packages:
126
+
127
+ ```
128
+ yarn build:dev
129
+ ```
130
+
121
131
## Building
122
132
123
- You can build the project with the following commands:
133
+ Build the project using one of these commands:
124
134
125
135
```
126
- // for local development - It stripped away operations that don't matter for local dev
136
+ // For local development (optimized, excludes production-only operations)
127
137
yarn build:dev
128
138
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)
130
140
yarn build
131
141
```
132
142
@@ -148,22 +158,6 @@ yarn test:local
148
158
149
159
` nx generate @nx/js:library `
150
160
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
-
167
161
## Building
168
162
169
163
``` sh
@@ -210,170 +204,216 @@ Having done this setup, this is what the development cycle looks like moving for
210
204
2 . Rebuild specific package
211
205
3 . Rebuild client application.
212
206
213
- ### Building changes to Rust source
207
+ ### Building Rust Components
214
208
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 ) .
216
210
217
- ## Publishing
211
+ ## Publishing New Versions
218
212
219
- You must have at least nodejs v18 to do this.
213
+ Prerequisites:
220
214
221
- 1 . Install the latest packages with ` yarn install `
215
+ - Node.js v18.0.0 or later
222
216
223
- 2 . Run ` yarn bump ` to bump the version
217
+ Publishing steps:
224
218
225
- 3 . Build all the packages with ` yarn build `
219
+ 1 . Create a release PR:
226
220
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
228
225
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"
230
236
231
- 6 . Finally, publish with ` yarn publish:packages `
237
+ ## Testing Guide
232
238
233
- 7 . Commit these changes "Published version X.X.X"
239
+ ### Available Test Commands
234
240
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 |
236
245
237
- ### Quick Start on E2E Testing
246
+ ### Running Tests
238
247
239
- The following will serve the react testing app and launch the cypress e2e testing after
248
+ 1 . Unit Tests:
240
249
241
- ``` sh
242
- yarn test:local
243
- ```
250
+ ``` sh
251
+ yarn test:unit
252
+ ```
244
253
245
- ### Unit Tests
254
+ 2 . End-to-End Tests:
246
255
247
- ``` sh
248
- yarn test:unit
249
- ```
256
+ ``` sh
257
+ yarn test:local
258
+ ```
250
259
251
- ## Testing with a Local Lit Node
260
+ Optional Environment Variables:
252
261
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
254
264
255
- Set these two env vars :
265
+ Optional Flags :
256
266
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 >
261
268
262
- Run:
269
+ See more in ` local-tests/README.md `
263
270
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 ` )
269
276
270
- To run manual tests :
277
+ 2 . Configure environment variables :
271
278
272
279
``` 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"
274
285
```
275
286
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 |
277
294
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
281
296
282
- # Error Handling
297
+ ## Overview
283
298
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:
287
300
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
289
309
290
310
``` ts
291
311
import { VError } from ' @openagenda/verror' ;
292
312
import { LitNodeClientBadConfigError } from ' @lit-protocol/constants' ;
293
313
294
314
try {
315
+ // Simulate an error condition
295
316
const someNativeError = new Error (' some native error' );
296
317
318
+ // Throw a Lit-specific error with context
297
319
throw new LitNodeClientBadConfigError (
298
320
{
299
321
cause: someNativeError ,
300
- info: {
301
- foo: ' bar' ,
302
- },
303
- meta: {
304
- baz: ' qux' ,
305
- },
322
+ info: { foo: ' bar' },
323
+ meta: { baz: ' qux' },
306
324
},
307
325
' some useful message'
308
326
);
309
327
} catch (e ) {
328
+ // Access error details
310
329
console .log (e .name ); // LitNodeClientBadConfigError
311
330
console .log (e .message ); // some useful message: some native error
312
331
console .log (e .info ); // { foo: 'bar' }
313
332
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
318
339
}
319
340
```
320
341
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
+ ```
331
364
332
365
# Dockerfile
333
366
334
367
...coming soon
335
368
336
369
## Other Commands
337
370
338
- ### Interactive graph dependencies using NX
371
+ # Core Systems and Services
339
372
340
- ```
341
- yarn graph
342
- ```
373
+ The Lit Protocol SDK provides the following core systems:
343
374
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
345
381
346
- # FAQs & Common Errors
382
+ # Main Functions and Classes
347
383
348
- <details >
349
- <summary >(React) Failed to parse source map from</summary >
384
+ Key components available across packages:
350
385
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
352
392
353
- eg.
393
+ # Troubleshooting Guide
354
394
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
363
398
364
- </ details >
399
+ ** Problem: ** "Reference Error: crypto is not defined"
365
400
366
- < details >
367
- < summary >Reference Error: crypto is not defined</ summary >
401
+ ** Solution: **
402
+ Add the following polyfill for environments without native crypto:
368
403
369
404
``` js
370
405
import crypto , { createHash } from ' crypto' ;
406
+
407
+ // Add crypto to global scope
371
408
Object .defineProperty (globalThis , ' crypto' , {
372
409
value: {
410
+ // Implement getRandomValues
373
411
getRandomValues : (arr : any ) => crypto .randomBytes (arr .length ),
412
+
413
+ // Implement subtle crypto
374
414
subtle: {
375
415
digest : (algorithm : string , data : Uint8Array ) => {
376
- return new Promise ((resolve , reject ) =>
416
+ return new Promise ((resolve ) =>
377
417
resolve (
378
418
createHash (algorithm .toLowerCase ().replace (' -' , ' ' ))
379
419
.update (data)
@@ -386,10 +426,9 @@ Object.defineProperty(globalThis, 'crypto', {
386
426
});
387
427
```
388
428
389
- </details >
390
- <details >
391
- <summary >error Command failed with exit code 13.</summary >
429
+ ### Unexpected Error on Node
392
430
393
- Make sure your node version is above v18.0.0
431
+ ** Problem: ** Exit code 13
394
432
395
- </details >
433
+ ** Solution:**
434
+ Make sure your node version is above v18.0.0
0 commit comments