diff --git a/README.md b/README.md index 4a9826db2..ba6bd7d47 100644 --- a/README.md +++ b/README.md @@ -1,294 +1,156 @@
-

Lit Protocol Javascript/Typescript SDK V8.x.x

- - -
- -
-
-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: -
-
- ---- - -
-

Lit Protocol Javascript/Typescript SDK V7.x.x

- - -
- -
-
-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 - - +

Lit Protocol Javascript/Typescript SDK V8.x.x

+ +
+ + + +
+
+ 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 +
-
- # Quick Start -### NodeJS Exclusive +The `@lit-protocol/lit-client` package is the core interface for interacting with the Lit Protocol network, and is operable in both Node.js and the browser. -Removed browser-specific methods, e.g., checkAndSignAuthSig +Install with your preferred package manager: ``` -yarn add @lit-protocol/lit-node-client-nodejs +yarn add @lit-protocol/lit-client ``` -or.. +# Packages -### Isomorphic Implementation + +
-Operable in both Node.js and the browser - -``` -yarn add @lit-protocol/lit-node-client -``` +| Package | Category | Download | +| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [@lit-protocol/lit-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-client) | ![lit-client](https://img.shields.io/badge/-universal-8A6496 "lit-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:
-# Packages - -📝 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 | -| ------- | -------- | -------- | - -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:: - | Package | Category | Download | | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 'access-control-conditions') | | -| [@lit-protocol/access-control-conditions-schemas](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions-schemas) | ![access-control-conditions-schemas](https://img.shields.io/badge/-universal-8A6496 'access-control-conditions-schemas') | | -| [@lit-protocol/auth](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth) | ![auth](https://img.shields.io/badge/-universal-8A6496 'auth') | | -| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 'auth-helpers') | | -| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 'constants') | | -| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 'crypto') | | -| [@lit-protocol/lit-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-client) | ![lit-client](https://img.shields.io/badge/-universal-8A6496 'lit-client') | | -| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 'logger') | | -| [@lit-protocol/networks](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/networks) | ![networks](https://img.shields.io/badge/-universal-8A6496 'networks') | | -| [@lit-protocol/schemas](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/schemas) | ![schemas](https://img.shields.io/badge/-universal-8A6496 'schemas') | | -| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 'types') | | -| [@lit-protocol/wasm](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wasm) | ![wasm](https://img.shields.io/badge/-universal-8A6496 'wasm') | | -| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 'wrapped-keys') | | -| [@lit-protocol/wrapped-keys-lit-actions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys-lit-actions) | ![wrapped-keys-lit-actions](https://img.shields.io/badge/-universal-8A6496 'wrapped-keys-lit-actions') | | +| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 "access-control-conditions") | | +| [@lit-protocol/access-control-conditions-schemas](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions-schemas) | ![access-control-conditions-schemas](https://img.shields.io/badge/-universal-8A6496 "access-control-conditions-schemas") | | +| [@lit-protocol/auth](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth) | ![auth](https://img.shields.io/badge/-universal-8A6496 "auth") | | +| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 "auth-helpers") | | +| [@lit-protocol/auth-services](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-services) | ![auth-services](https://img.shields.io/badge/-universal-8A6496 "auth-services") | | +| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 "constants") | | +| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 "crypto") | | +| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 "logger") | | +| [@lit-protocol/networks](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/networks) | ![networks](https://img.shields.io/badge/-universal-8A6496 "networks") | | +| [@lit-protocol/schemas](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/schemas) | ![schemas](https://img.shields.io/badge/-universal-8A6496 "schemas") | | +| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 "types") | | +| [@lit-protocol/wasm](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wasm) | ![wasm](https://img.shields.io/badge/-universal-8A6496 "wasm") | | +| [@lit-protocol/wrapped-keys](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys) | ![wrapped-keys](https://img.shields.io/badge/-universal-8A6496 "wrapped-keys") | | +| [@lit-protocol/wrapped-keys-lit-actions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/wrapped-keys-lit-actions) | ![wrapped-keys-lit-actions](https://img.shields.io/badge/-universal-8A6496 "wrapped-keys-lit-actions") | | + +
-## API Doc +## API Docs -| Version | Link | -| ------------ | -------------------------------------------------------- | -| V7 (Current) | [7.x.x docs](https://v7-api-doc-lit-js-sdk.vercel.app/) | -| V6 | [6.x.x docs](https://v6-api-doc-lit-js-sdk.vercel.app/) | -| V5 | [5.x.x docs](https://v3.api-docs.getlit.dev/) | -| V2 | [2.x.x docs](http://docs.lit-js-sdk-v2.litprotocol.com/) | +
+ +| Version | Link | +| ------- | -------------------------------------------------------- | +| V8 | TBD | +| V7 | [7.x.x docs](https://v7-api-doc-lit-js-sdk.vercel.app/) | +| V6 | [6.x.x docs](https://v6-api-doc-lit-js-sdk.vercel.app/) | +| V5 | [5.x.x docs](https://v3.api-docs.getlit.dev/) | +| V2 | [2.x.x docs](http://docs.lit-js-sdk-v2.litprotocol.com/) |
-# Contributing and developing to this SDK +# Contributing to this SDK -## Prerequisite +### Prerequisites - node (v20.x or above) -- rust (v1.70.00 or above) +- bun (v1.2.10) +- python (v3.11.9 distutils is required) +- rust (v1.82.0 or above) - [wasm-pack](https://github.com/rustwasm/wasm-pack) -## Recommended +### Recommended - NX Console: https://nx.dev/core-features/integrate-with-editors -# Quick Start +## Quick Start The following commands will help you start developing with this repository. -First, install the dependencies via yarn: +First, install the dependencies via bun: ``` -yarn +bun install ``` ## Building -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 -``` - -## Run unit tests - -``` -yarn test:unit -``` - -## Run E2E tests in nodejs - -``` -yarn test:local -``` - -# Advanced - -## Creating a new library - -`nx generate @nx/js:library` - -## Create a new react demo app using the Lit JS SDK - -```sh -yarn tools --create --react contracts-sdk --demo -``` - -## Deleting a package or app - -``` -// delete an app from ./app/ -yarn delete:app - -// delete a package from ./packages/ -yarn delete:package -``` - -## Building - -```sh -yarn build -``` - -### Building target package +You can build the project with the following command: -```sh -yarn nx run :build ``` +// The command unlinks all packages, fixes missing dependencies, +// and then builds all packages sequentially (excluding wrapped-keys packages) +// to ensure a clean and complete build. +bun run build -## Building 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: - -1. Run `npm link` at the root of the specific package you are making code changes in. - -``` -cd ./packages/*/ -npm link +// Automatically fixes missing dependencies across all packages and +// then builds only the affected packages (excluding wrapped-keys packages) +// to optimize build time. +bun run build:affected ``` -2. Build the packages with or without dependencies - -``` -yarn build -# or -yarn nx run lit-node-client-nodejs:build --with-deps=false -``` +### Building a Specific Package -3. In the client application, run `npm link --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. +To build a specific package, run the following command: ``` -cd path/to/client-application -npm link --save +bunx nx run :build ``` -Having done this setup, this is what the development cycle looks like moving forward: - -1. Make code change -2. Rebuild specific package -3. Rebuild client application. - ### Building changes to Rust source If changes are made to `packages/wasm` see [here](./packages/wasm/README.md) for info on building from source. -## Publishing - -You must have at least nodejs v18 to do this. - -1. Install the latest packages with `yarn install` - -2. Run `yarn bump` to bump the version - -3. Build all the packages with `yarn build` - -4. Run the unit tests with `yarn test:unit` & e2e node tests `yarn test:local` locally & ensure that they pass - -5. Update the docs with `yarn gen:docs --push` - -6. Finally, publish with `yarn publish:packages` - -7. Commit these changes "Published version X.X.X" - ## Testing -### Quick Start on E2E Testing - -The following will serve the react testing app and launch the cypress e2e testing after +Run local unit tests once with: -```sh -yarn test:local ``` - -### Unit Tests - -```sh -yarn test:unit -``` - -## Testing 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: - -```sh -export LIT_JS_SDK_LOCAL_NODE_DEV="true" -export LIT_JS_SDK_FUNDED_WALLET_PRIVATE_KEY="putAFundedPrivateKeyOnChronicleHere" +bun run test:unit ``` -Run: +or continuously as changes are made with: -```sh -yarn update:contracts-sdk --fetch -yarn update:contracts-sdk --gen -yarn build:packages ``` - -To run manual tests: - -```sh - yarn nx run nodejs:serve +bun run test:unit:watch ``` -## ENV 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 - -# Error Handling +## Error Handling 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. 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. -## Example +### Example ```ts import { VError } from '@openagenda/verror'; @@ -331,68 +193,3 @@ To create and use a new error, you need to: 2. Export the error from the `errors.ts` file at the end of the file 3. Import the error where you need it 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. - -# Dockerfile - -...coming soon - -## Other Commands - -### Interactive graph dependencies using NX - -``` -yarn graph -``` - -![](https://i.ibb.co/2dLyMTW/Screenshot-2022-11-15-at-15-18-46.png) - -# FAQs & Common Errors - -
-(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 - -```js -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 - -
diff --git a/packages/auth-services/package.json b/packages/auth-services/package.json index 92ae05b48..e5782a92d 100644 --- a/packages/auth-services/package.json +++ b/packages/auth-services/package.json @@ -3,6 +3,9 @@ "version": "1.0.0-alpha.23", "license": "MIT", "type": "module", + "tags": [ + "universal" + ], "main": "./src/index.js", "types": "./src/index.d.ts", "scripts": { diff --git a/tools/scripts/gen-readme.mjs b/tools/scripts/gen-readme.mjs index 240e8d1dd..a42271209 100644 --- a/tools/scripts/gen-readme.mjs +++ b/tools/scripts/gen-readme.mjs @@ -87,8 +87,7 @@ libs.map((lib) => { let rows = [...bundled, ...universals, ...browsers, ...nodejs]; let mainModules = [ - '@lit-protocol/lit-node-client', - '@lit-protocol/lit-node-client-nodejs', + '@lit-protocol/lit-client', ]; let mainRows = []; let otherRows = []; @@ -136,13 +135,15 @@ ${body} let mainContent = table(tables.headers, tables.mainRows); let otherContent = - "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::\n\n" + - table(tables.headers, tables.otherRows); + "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:\n" + + "\n
\n" + + table(tables.headers, tables.otherRows) + + "\n
\n"; // use regex to replace the content between the comments and const newReadme = readme.replace( /[\s\S]*/m, - `\n${mainContent}\n\n${otherContent}\n` + `\n
\n${mainContent}\n
\n${otherContent}\n` ); // console.log(newReadme);