@overdive/lit-js-sdk v0.0.5
Quick Start
NodeJS Exclusive
Removed browser-specific methods, e.g., checkAndSignAuthSig
yarn add @overdive/lit-node-client-nodejsor..
Isomorphic Implementation
Operable in both Node.js and the browser
yarn add @overdive/lit-node-clientPackages
📝 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 |
|---|---|---|
| @overdive/lit-node-client-nodejs | ||
| @overdive/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::
API Doc
| Version | Link |
|---|---|
| V6 (Beta) | 6.x.x docs |
| V5 (Current) | 5.x.x docs |
| V2 | 2.x.x docs |
Contributing and developing to this SDK
Prerequisite
- node (v19.x or above)
Recommended
Quick Start
The following commands will help you start developing with this repository.
First, install the dependencies via yarn:
yarnBuilding
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 buildRun unit tests
yarn test:unitRun E2E tests in nodejs
yarn test:localAdvanced
Creating a new library
nx generate @nx/js:library
Create a new react demo app using the Lit JS SDK
yarn tools --create --react contracts-sdk --demoDeleting a package or app
// delete an app from ./app/<app-name>
yarn delete:app <app-name>
// delete a package from ./packages/<package-name>
yarn delete:package <package-name>Building
yarn buildBuilding target package
yarn nx run <project-name>:buildBuilding Local Changes
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 linkat 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> --saveto ensure that thepackage.jsonof the client application is updated with afile:link to the dependency. This effectively creates a symlink in thenode_modulesof the client application to the local dependency in this repository.
cd path/to/client-application
npm link <package> --saveHaving done this setup, this is what the development cycle looks like moving forward:
- Make code change
- Rebuild specific package
- Rebuild client application.
Publishing
You must have at least nodejs v18 to do this.
Install the latest packages with
yarn installRun
yarn bumpto bump the versionBuild all the packages with
yarn buildRun the unit tests with
yarn test:unit& e2e node testsyarn test:locallocally & ensure that they passUpdate the docs with
yarn gen:docs --pushFinally, publish with the
@cayennetag:yarn publish:cayenneCommit these changes "Published version X.X.X"
Publishing to Serrano / Jalapno
git checkout serrano
yarn bump
yarn build
yarn node ./tools/scripts/pub.mjs --tag serrano-jalapenoTesting
Quick Start on E2E Testing
The following will serve the react testing app and launch the cypress e2e testing after
yarn test:localUnit Tests
yarn test:unitTesting with a Local Lit Node
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:packagesTo run manual tests:
yarn nx run nodejs:serveENV Vars
- 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
Dockerfile
...coming soon
Other Commands
Interactive graph dependencies using NX
yarn graph
FAQs & Common Errors
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"
},It’s currently using a custom plugin @websaam/nx-esbuild which is a fork from @wanews/nx-esbuild
"_buildWeb": {
"executor": "@websaam/nx-esbuild:package",
"options": {
"banner": {
"js": "import { createRequire } from 'module';const require = createRequire(import.meta.url);"
},
"globalName": "LitJsSdk_CoreBrowser",
"outfile":"dist/packages/core-browser-vanilla/core-browser.js",
"entryPoints": ["./packages/core-browser/src/index.ts"],
"define": { "global": "window" },
"plugins":[
{
"package": "esbuild-node-builtins",
"function": "nodeBuiltIns"
}
]
}
}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()
)
);
},
},
},
});Make sure your node version is above v18.0.0