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 |
Before you begin, ensure you have the following installed:
Recommended for better development experience:
To start developing with this repository:
yarn
yarn build:dev
Build the project using one of these commands:
// For local development (optimized, excludes production-only operations)
yarn build:dev
// For testing and publishing (full build with all operations)
yarn build
yarn test:unit
yarn test:local
nx generate @nx/js:library
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:
npm link
at the root of the specific package you are making code changes in.cd ./packages/*/<package-name>
npm link
yarn build
# or
yarn nx run lit-node-client-nodejs:build --with-deps=false
npm link <package> --save
to ensure that the package.json
of the client application is updated with a file:
link to the dependency. This effectively creates a symlink in the node_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:
For changes to WebAssembly components in packages/wasm
, refer to the WebAssembly build guide.
Prerequisites:
Publishing steps:
Create a release PR:
vX.X.X-Publish
After PR approval, proceed with publishing:
yarn install
yarn bump
yarn build
yarn test:unit
yarn test:local
yarn gen:docs --push
yarn publish:packages
Command | Description |
---|---|
yarn test:unit |
Run unit tests for all packages |
yarn test:local |
Run E2E tests in Node.js environment |
Unit Tests:
yarn test:unit
End-to-End Tests:
yarn test:local
Optional Environment Variables:
Optional Flags:
See more in local-tests/README.md
Deploy Lit Node Contracts (addresses will be read from ../lit-assets/blockchain/contracts/deployed-lit-node-contracts-temp.json
)
Configure environment variables:
# Enable local node development
export LIT_JS_SDK_LOCAL_NODE_DEV="true"
# Set funded wallet for Chronicle testnet
export LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY="your-funded-private-key"
Variable | Description | Usage |
---|---|---|
LIT_JS_SDK_GITHUB_ACCESS_TOKEN |
GitHub access token | Required for accessing contract ABIs from private repository |
LIT_JS_SDK_LOCAL_NODE_DEV |
Local node development flag | Set to true to use a local Lit node |
LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY |
Funded wallet private key | Required for Chronicle Testnet transactions |
The SDK implements a robust error handling system using @openagenda/verror. This system provides:
import { VError } from '@openagenda/verror';
import { LitNodeClientBadConfigError } from '@lit-protocol/constants';
try {
// Simulate an error condition
const someNativeError = new Error('some native error');
// Throw a Lit-specific error with context
throw new LitNodeClientBadConfigError(
{
cause: someNativeError,
info: { foo: 'bar' },
meta: { baz: 'qux' },
},
'some useful message'
);
} catch (e) {
// Access error details
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
// Additional error information
// - VError.cause(e): Original error (someNativeError)
// - VError.info(e): Additional context ({ foo: 'bar' })
// - VError.meta(e): Metadata ({ baz: 'qux', code: 'lit_node_client_bad_config_error', kind: 'Config' })
// - VError.fullStack(e): Complete error chain stack trace
}
To add new error types:
packages/constants/src/lib/errors.ts
LIT_ERROR
objectthrow new YourCustomError(
{
cause: originalError,
info: {
/* context */
},
meta: {
/* metadata */
},
},
'Error message'
);
...coming soon
The Lit Protocol SDK provides the following core systems:
Key components available across packages:
PKPEthersWallet
: Ethereum wallet management for PKPLitNodeClient
: Network interaction clientexecuteJs()
: Decentralized JavaScript executionsignMessageWithEncryptedKey()
: Cryptographic signinggeneratePrivateKey()
: Key generation utilitiesTinnyEnvironment
: Testing environment setupProblem: "Reference Error: crypto is not defined"
Solution: Add the following polyfill for environments without native crypto:
import crypto, { createHash } from 'crypto';
// Add crypto to global scope
Object.defineProperty(globalThis, 'crypto', {
value: {
// Implement getRandomValues
getRandomValues: (arr: any) => crypto.randomBytes(arr.length),
// Implement subtle crypto
subtle: {
digest: (algorithm: string, data: Uint8Array) => {
return new Promise((resolve) =>
resolve(
createHash(algorithm.toLowerCase().replace('-', ''))
.update(data)
.digest()
)
);
},
},
},
});
Problem: Exit code 13
Solution: Make sure your node version is above v18.0.0