The Lit JavaScript SDK provides developers with a framework for implementing Lit functionality into their own applications. Find installation instructions in the docs to get started with the Lit SDK based on your use case:
https://developer.litprotocol.com/SDK/Explanation/installation
Removed browser-specific methods, e.g., checkAndSignAuthSig
yarn add @lit-protocol/lit-node-client-nodejs
or..
Operable in both Node.js and the browser
yarn add @lit-protocol/lit-node-client
đź“ť If you're looking to use the Lit SDK, you're probably all set with just the lit-node-client .
Get started with interacting with Lit network!
Package | Category | Download |
---|---|---|
@lit-protocol/lit-node-client-nodejs | ||
@lit-protocol/lit-node-client |
If you're a tech-savvy user and wish to utilize only specific submodules that our main module relies upon, you can find individual packages listed below. This way, you can import only the necessary packages that cater to your specific use case::
Version | Link |
---|---|
V7 (Current) | 7.x.x docs |
V6 | 6.x.x docs |
V5 | 5.x.x docs |
V2 | 2.x.x docs |
- node (v19.x or above)
- rust (v1.70.00 or above)
- wasm-pack
The following commands will help you start developing with this repository.
First, install the dependencies via yarn:
yarn
You can build the project with the following commands:
// for local development - It stripped away operations that don't matter for local dev
yarn build:dev
// you should never need to use yarn build unless you want to test or publish it
yarn build
yarn test:unit
yarn test:local
nx generate @nx/js:library
yarn tools --create --react contracts-sdk --demo
// delete an app from ./app/<app-name>
yarn delete:app <app-name>
// delete a package from ./packages/<package-name>
yarn delete:package <package-name>
yarn build
yarn nx run <project-name>:build
During development you may wish to build your code changes in packages/
in a client application to test the correctness of the functionality.
If you would like to establish a dependency between packages within this monorepo and an external client application that consumes these packages:
- Run
npm link
at the root of the specific package you are making code changes in.
cd ./packages/*/<package-name>
npm link
- Build the packages with or without dependencies
yarn build
# or
yarn nx run lit-node-client-nodejs:build --with-deps=false
- In the client application, run
npm link <package> --save
to ensure that thepackage.json
of the client application is updated with afile:
link to the dependency. This effectively creates a symlink in thenode_modules
of the client application to the local dependency in this repository.
cd path/to/client-application
npm link <package> --save
Having done this setup, this is what the development cycle looks like moving forward:
- Make code change
- Rebuild specific package
- Rebuild client application.
If changes are made to packages/wasm
see here for info on building from source.
You must have at least nodejs v18 to do this.
-
Install the latest packages with
yarn install
-
Run
yarn bump
to bump the version -
Build all the packages with
yarn build
-
Run the unit tests with
yarn test:unit
& e2e node testsyarn test:local
locally & ensure that they pass -
Update the docs with
yarn gen:docs --push
-
Finally, publish with
yarn publish:packages
-
Commit these changes "Published version X.X.X"
The following will serve the react testing app and launch the cypress e2e testing after
yarn test:local
yarn test:unit
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.
Set these two env vars:
export LIT_JS_SDK_LOCAL_NODE_DEV="true"
export LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY="putAFundedPrivateKeyOnChronicleHere"
Run:
yarn update:contracts-sdk --fetch
yarn update:contracts-sdk --gen
yarn build:packages
To run manual tests:
yarn nx run nodejs:serve
- LIT_JS_SDK_GITHUB_ACCESS_TOKEN - a github access token to get the contract ABIs from a private repo
- LIT_JS_SDK_LOCAL_NODE_DEV - set to true to use a local node
- LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY - set to a funded wallet on Chronicle Testnet
This SDK uses custom error classes derived from @openagenda/verror to handle errors between packages and to the SDK consumers. Normal error handling is also supported as VError extends the native Error class, but using VError allows for better error composition and information propagation. 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.
import { VError } from '@openagenda/verror';
import { LitNodeClientBadConfigError } from '@lit-protocol/constants';
try {
const someNativeError = new Error('some native error');
throw new LitNodeClientBadConfigError(
{
cause: someNativeError,
info: {
foo: 'bar',
},
meta: {
baz: 'qux',
},
},
'some useful message'
);
} catch (e) {
console.log(e.name); // LitNodeClientBadConfigError
console.log(e.message); // some useful message: some native error
console.log(e.info); // { foo: 'bar' }
console.log(e.baz); // qux
// VError.cause(e) is someNativeError
// VError.info(e) is { foo: 'bar' }
// VError.meta(e) is { baz: 'qux', code: 'lit_node_client_bad_config_error', kind: 'Config' }
// Verror.fullStack(e) is the full stack trace composed of the error chain including the causes
}
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.
To create and use a new error, you need to:
- Add the error information to the
LIT_ERROR
object inpackages/constants/src/lib/errors.ts
- Export the error from the
errors.ts
file at the end of the file - Import the error where you need it
- 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.
...coming soon
yarn graph
(React) Failed to parse source map from
In your React package.json, add GENERATE_SOURCEMAP=false
to your start script
eg.
"scripts": {
"start": "GENERATE_SOURCEMAP=false react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Reference Error: crypto is not defined
import crypto, { createHash } from 'crypto';
Object.defineProperty(globalThis, 'crypto', {
value: {
getRandomValues: (arr: any) => crypto.randomBytes(arr.length),
subtle: {
digest: (algorithm: string, data: Uint8Array) => {
return new Promise((resolve, reject) =>
resolve(
createHash(algorithm.toLowerCase().replace('-', ''))
.update(data)
.digest()
)
);
},
},
},
});
error Command failed with exit code 13.
Make sure your node version is above v18.0.0