Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-SDK README cleanup/writeup/contribution #756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,6 @@ yarn test:local

`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/<app-name>
yarn delete:app <app-name>

// delete a package from ./packages/<package-name>
yarn delete:package <package-name>
```

## Building

```sh
Expand Down Expand Up @@ -275,9 +259,11 @@ To run manual tests:

## 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
| Variable | Description |
| -------- | ----------- |
| 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

Expand Down
2 changes: 1 addition & 1 deletion packages/constants/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Quick Start

This submodule exports various modules, constants, interfaces, errors, utilities that are being used in Lit Protocol.
This submodule exports various modules, constants, interfaces, errors, and utilities that are used in the Lit Protocol.

### node.js / browser

Expand Down
8 changes: 7 additions & 1 deletion packages/core/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# core

This library was generated with [Nx](https://nx.dev).
This submodule provides core functionalities for the Lit Protocol, including the main LitNodeClient class, which is used to interact with the Lit network. It also includes various utility functions and constants that are used throughout the SDK.

### node.js / browser

```
yarn add @lit-protocol/core
```

## Building

Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Quick Start

This submodule provides encryption and decryption of contents (string, file, etc.) respectively using a symmetric key, with the encrypted content returned as a Blob and the symmetric key as a Uint8Array
This submodule provides encryption and decryption of contents (string, file, etc.) respectively using a symmetric key, with the encrypted content returned as a Blob and the symmetric key as a Uint8Array.

### node.js / browser

Expand Down
24 changes: 24 additions & 0 deletions packages/lit-node-client-nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This `LitNodeClientNodeJs` is created solely to run on Node.js.

The usual `checkAndSignAuthMessage` is not included in this package, so you need to add it manually to the constructor if you decide to use it on a browser, or with any custom auth callback.

This package provides functionalities to interact with the Lit network in a Node.js environment.

## Installation

```bash
yarn add @lit-protocol/lit-node-client-nodejs
```

## Usage

```js
import * as LitJsSdkNodeJs from '@lit-protocol/lit-node-client-nodejs';
import { checkAndSignAuthMessage } from '@lit-protocol/auth-browser';
Expand All @@ -19,3 +29,17 @@ const authSig = await checkAndSignAuthMessage({
chain: 'ethereum',
});
```

## Contributing

We welcome contributions to the `lit-node-client-nodejs` package. Please follow the guidelines below to contribute:

1. Fork the repository.
2. Create a new branch for your feature or bugfix.
3. Make your changes.
4. Ensure all tests pass.
5. Submit a pull request.

## License

This project is licensed under the MIT License.
8 changes: 7 additions & 1 deletion packages/logger/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# logger

This library was generated with [Nx](https://nx.dev).
This submodule provides logging functionalities for the Lit Protocol, including methods for logging messages with different levels of severity (info, warn, error).

### node.js / browser

```
yarn add @lit-protocol/logger
```

## Building

Expand Down
70 changes: 70 additions & 0 deletions packages/misc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,73 @@ This submodule contains various utility functions for error handling, logging, t
```
yarn add @lit-protocol/misc
```

## Description

The `@lit-protocol/misc` package provides a collection of utility functions that are commonly used across different modules of the Lit Protocol SDK. These utilities include functions for error handling, logging, type checking, and other miscellaneous operations that help in the development and maintenance of the SDK.

## Installation

To install the `@lit-protocol/misc` package, you can use either npm or yarn:

```bash
npm install @lit-protocol/misc
```

or

```bash
yarn add @lit-protocol/misc
```

## Usage

Here are some examples of how to use the utility functions provided by the `@lit-protocol/misc` package:

### Error Handling

The `@lit-protocol/misc` package provides utility functions for error handling, such as creating custom error classes and handling errors in a consistent manner.

```javascript
import { createCustomError } from '@lit-protocol/misc';

class MyCustomError extends createCustomError('MyCustomError') {}

try {
throw new MyCustomError('Something went wrong');
} catch (error) {
console.error(error.message); // Output: Something went wrong
}
```

### Logging

The `@lit-protocol/misc` package includes utility functions for logging messages with different log levels, such as info, warning, and error.

```javascript
import { logInfo, logWarning, logError } from '@lit-protocol/misc';

logInfo('This is an informational message');
logWarning('This is a warning message');
logError('This is an error message');
```

### Type Checking

The `@lit-protocol/misc` package provides utility functions for type checking, such as checking if a value is of a specific type.

```javascript
import { isString, isNumber, isArray } from '@lit-protocol/misc';

console.log(isString('Hello')); // Output: true
console.log(isNumber(123)); // Output: true
console.log(isArray([1, 2, 3])); // Output: true
```

## Contributing

We welcome contributions to the `@lit-protocol/misc` package. If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on the GitHub repository.

## License

The `@lit-protocol/misc` package is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
104 changes: 103 additions & 1 deletion packages/nacl/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,111 @@
# Quick Start

re-export of https://www.npmjs.com/package/nacl
This submodule provides a re-export of the `nacl` package, which is a cryptographic library for handling various encryption and decryption operations.

### node.js / browser

```
yarn add @lit-protocol/nacl
```

## Description

The `@lit-protocol/nacl` package is a wrapper around the `nacl` library, providing cryptographic functionalities such as public-key encryption, secret-key encryption, digital signatures, and hashing. It is designed to be used in both Node.js and browser environments.

## Installation

To install the `@lit-protocol/nacl` package, you can use either npm or yarn:

```bash
npm install @lit-protocol/nacl
```

or

```bash
yarn add @lit-protocol/nacl
```

## Usage

Here are some examples of how to use the cryptographic functions provided by the `@lit-protocol/nacl` package:

### Public-Key Encryption

The `@lit-protocol/nacl` package provides functions for public-key encryption, allowing you to encrypt and decrypt messages using a pair of public and private keys.

```javascript
import nacl from '@lit-protocol/nacl';

// Generate a new key pair
const keyPair = nacl.box.keyPair();

// Encrypt a message
const message = new TextEncoder().encode('Hello, world!');
const nonce = nacl.randomBytes(nacl.box.nonceLength);
const encryptedMessage = nacl.box(message, nonce, keyPair.publicKey, keyPair.secretKey);

// Decrypt the message
const decryptedMessage = nacl.box.open(encryptedMessage, nonce, keyPair.publicKey, keyPair.secretKey);
console.log(new TextDecoder().decode(decryptedMessage)); // Output: Hello, world!
```

### Secret-Key Encryption

The `@lit-protocol/nacl` package also provides functions for secret-key encryption, allowing you to encrypt and decrypt messages using a shared secret key.

```javascript
import nacl from '@lit-protocol/nacl';

// Generate a new secret key
const secretKey = nacl.randomBytes(nacl.secretbox.keyLength);

// Encrypt a message
const message = new TextEncoder().encode('Hello, world!');
const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);
const encryptedMessage = nacl.secretbox(message, nonce, secretKey);

// Decrypt the message
const decryptedMessage = nacl.secretbox.open(encryptedMessage, nonce, secretKey);
console.log(new TextDecoder().decode(decryptedMessage)); // Output: Hello, world!
```

### Digital Signatures

The `@lit-protocol/nacl` package provides functions for creating and verifying digital signatures, allowing you to sign messages and verify the authenticity of signed messages.

```javascript
import nacl from '@lit-protocol/nacl';

// Generate a new key pair
const keyPair = nacl.sign.keyPair();

// Sign a message
const message = new TextEncoder().encode('Hello, world!');
const signedMessage = nacl.sign(message, keyPair.secretKey);

// Verify the signed message
const verifiedMessage = nacl.sign.open(signedMessage, keyPair.publicKey);
console.log(new TextDecoder().decode(verifiedMessage)); // Output: Hello, world!
```

### Hashing

The `@lit-protocol/nacl` package provides functions for hashing messages, allowing you to create cryptographic hashes of messages.

```javascript
import nacl from '@lit-protocol/nacl';

// Hash a message
const message = new TextEncoder().encode('Hello, world!');
const hash = nacl.hash(message);
console.log(hash);
```

## Contributing

We welcome contributions to the `@lit-protocol/nacl` package. If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on the GitHub repository.

## License

The `@lit-protocol/nacl` package is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
77 changes: 77 additions & 0 deletions packages/pkp-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,80 @@ This submodule defines a PKPBase class, providing shared wallet functionality fo
```
yarn add @lit-protocol/pkp-base
```

## Description

The `@lit-protocol/pkp-base` package provides a foundational class for managing PKP (Public Key Pair) signers. This class offers shared wallet functionality, including public key compression, initialization and connection to the LIT node, execution of LIT actions, and debugging capabilities.

## Installation

To install the `@lit-protocol/pkp-base` package, you can use either npm or yarn:

```bash
npm install @lit-protocol/pkp-base
```

or

```bash
yarn add @lit-protocol/pkp-base
```

## Usage

Here are some examples of how to use the `PKPBase` class provided by the `@lit-protocol/pkp-base` package:

### Compressing a Public Key

The `compressPubKey` method allows you to compress a provided public key.

```javascript
import { PKPBase } from '@lit-protocol/pkp-base';

const pkpBase = new PKPBase();
const compressedPubKey = pkpBase.compressPubKey('your-public-key');
console.log(compressedPubKey);
```

### Setting Uncompressed Public Key and Buffer

The `setUncompressPubKeyAndBuffer` method sets the uncompressed public key and its buffer representation.

```javascript
import { PKPBase } from '@lit-protocol/pkp-base';

const pkpBase = new PKPBase();
pkpBase.setUncompressPubKeyAndBuffer({ pubKey: 'your-public-key' });
```

### Initializing the PKPBase Instance

The `init` method initializes the PKPBase instance by connecting to the LIT node.

```javascript
import { PKPBase } from '@lit-protocol/pkp-base';

const pkpBase = new PKPBase();
await pkpBase.init();
```

### Running a LIT Action

The `runLitAction` method runs the specified LIT action with the given parameters.

```javascript
import { PKPBase } from '@lit-protocol/pkp-base';

const pkpBase = new PKPBase();
const toSign = new Uint8Array([/* your data */]);
const sigName = 'your-signature-name';
await pkpBase.runLitAction(toSign, sigName);
```

## Contributing

We welcome contributions to the `@lit-protocol/pkp-base` package. If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on the GitHub repository.

## License

The `@lit-protocol/pkp-base` package is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.