forked from kingzamzon/docs
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from LIT-Protocol/wyatt/getting-started
Copy over Getting Started guides from docs overhaul
- Loading branch information
Showing
8 changed files
with
745 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Connecting to Lit | ||
|
||
The `LitNodeClient` is used to connect your session to the Lit network. After initializing a `LitNodeClient` instance, you can use the `connect()` method to establish a connection. | ||
|
||
When initializing a `LitNodeClient` instance, you must provide a `litNetwork`. | ||
|
||
```tsx | ||
import { LitNodeClient } from '@lit-protocol/lit-node-client'; | ||
import { LitNetwork } from '@lit-protocol/constants'; | ||
|
||
const litNodeClient = new LitNodeClient({ | ||
litNetwork: LitNetwork.DatilDev, | ||
debug: false, | ||
}); | ||
|
||
await litNodeClient.connect(); | ||
``` | ||
|
||
### `LitNetwork` Constant | ||
|
||
The `LitNetwork` constant contains the past and present Lit networks. The constant is imported from the `@lit-protocol/constants` package. The current networks in the constant can be found [here](https://v6-api-doc-lit-js-sdk.vercel.app/enums/constants_src.LitNetwork.html). | ||
|
||
### `LitNodeClient` Flags | ||
|
||
You have the option to pass flags to the `LitNodeClient` instance. These flags are used to configure the Lit network connection. You can find a complete list of flags in the [LitNodeClient Config](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.LitNodeClientConfig.html). In this guide we will cover the most common flags: `debug` and `storageProvider`. | ||
|
||
#### `debug` | ||
|
||
The `debug` flag is used to enable or disable debug logging. When enabled, debug logs will be written to the console. This flag will only provide debug logs when executing in a Node.js environment. In a browser environment, the `debug` flag will be ignored. | ||
|
||
#### `storageProvider` | ||
|
||
The `storageProvider` flag is used to configure the storage provider used by the Lit network. When provided, the Session Keypair will be stored in the provided storage. | ||
|
||
If not provided, a new Session Keypair will be generated each time the `LitNodeClient` is initialized. | ||
|
||
In a browser environment, the `storageProvider` flag will be ignored, and the Session Keypair will be stored in the browser's local storage. To clear the cached Session Keypair, you can use the `disconnectWeb3` function (imported from the `@lit-protocol/auth-browser` package) like so: | ||
|
||
```ts | ||
import { LitNodeClient } from '@lit-protocol/lit-node-client'; | ||
import { LitNetwork } from '@lit-protocol/constants'; | ||
import { disconnectWeb3 } from "@lit-protocol/auth-browser"; | ||
|
||
let litNodeClient; | ||
try { | ||
litNodeClient = new LitNodeClient({ | ||
litNetwork: LitNetwork.DatilDev, | ||
debug: false, | ||
}); | ||
|
||
await litNodeClient.connect(); | ||
} catch (error) { | ||
// handle errors | ||
} finally { | ||
disconnectWeb3(); // <--- When this function call is executed, | ||
// the Session Keypair will be deleted from the browser's local storage | ||
litNodeClient.disconnect(); // <--- Here we disconnect from the Lit network | ||
} | ||
``` | ||
|
||
### Disconnecting from the Lit Network | ||
|
||
To disconnect from the Lit network, you can use the `disconnect()` method on the `LitNodeClient` instance (as shown in the example above). This detaches Lit's listeners for contract changes and stops network polling. | ||
|
||
### Additional Support | ||
|
||
If you encounter any issues, providing the Lit team with your Lit request ID can help us resolve the problem faster. | ||
|
||
#### Node.js Environment | ||
|
||
In a Node.js environment, the request ID will be logged to the console when an error occurs. If this is not the case, you can enable debug logging by setting the `debug` flag to `true` in the `LitNodeClient` instance; the request ID will then be logged to the console. | ||
|
||
The following is an example log from `LitNodeClient` when `debug` was set to `true`: | ||
|
||
``` | ||
[Lit-JS-SDK v6.8.1] [2024-10-12T02:45:37.100Z] [DEBUG] [core] [id: a1eefc564ff6b] executeJs responseData from node | ||
``` | ||
|
||
`[id: a1eefc564ff6b]` is the Lit request ID that you should provide to the Lit team when making a support request. | ||
|
||
#### Browser Environment | ||
|
||
In a browser environment, the request ID will be logged to the console when an error occurs. If not, you can find the error in the **Network** tab of your browser's developer tools; scrolling to the bottom of the page will show the request ID. | ||
|
||
The following is an example of a response to a request made using `LitNodeClient` in the browser: | ||
|
||
![Lit Node Client Browser Request](../../../static/img/browser-request-id.png) | ||
|
||
`lit_62db9cad45377` is the Lit request ID that you should provide to the Lit team when making a support request. | ||
|
||
### API Reference | ||
|
||
To learn more about `LitNodeClient` properties and methods, visit the [API Reference Docs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/core_src.LitCore.html). | ||
|
||
### Code Example | ||
|
||
A short code example of connecting to the Lit network with a `LitNodeClient` instance can be found in our developer guides repo [here](https://github.com/LIT-Protocol/developer-guides-code/tree/master/starter-guides). There are examples for both Node.js and the browser. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Generating Session Signatures | ||
|
||
Before you can interact with the Lit network and start sending requests, you need to start a session using Session Signatures. This guide will walk you through creating your first session using the Lit SDK. | ||
|
||
:::info | ||
For a dedicated guide on Session Signatures, please see the detailed explanation [here](../../sdk/authentication/session-sigs/intro). | ||
::: | ||
|
||
## What is a Session? | ||
|
||
A Session is like a temporary pass that allows you to interact with the Lit network securely. It's a way to prove your identity and prove that you have the permissions to perform actions on the network, without having to sign every request with your private key. | ||
|
||
When you initiate a session by making a request to the Lit network using the Lit SDK, the SDK generates a Session Keypair, which consists of a public key and a private key: | ||
|
||
- **Session Private Key**: This key is kept secure and is used to sign your requests to the Lit network. | ||
- **Session Public Key**: This key is shared with the Lit network to establish your session. | ||
|
||
## How Session Signatures Are Generated | ||
|
||
Session Signatures are generated by the Lit nodes and they are a result of each node attesting to the fact that you have the permissions to perform actions with the requested resources on the Lit network. | ||
|
||
Here's an overview of how they're generated: | ||
|
||
1. **Session Keypair Generation**: You initiate a session by sending a request to the Lit network through the Lit SDK. | ||
2. **Authentication**: The Lit nodes receive your request and first authenticate your identity—confirming that you are who you claim to be. | ||
3. **Authorization**: The nodes then authorize you by checking if you have the necessary permissions to access the requested Lit resources and perform the desired actions with those resources. | ||
4. **Generating the Session Signature**: Once your identity is verified and you’re authorized, the Lit nodes sign the session public key. This signed public key is the Session Signature. | ||
5. **Using the Session Signature**: The Lit SDK collects these Session Signatures and packages them into an object. You attach this object to any subsequent requests you make to the Lit network. This Session Signatures object serves as proof that you are authorized to make your requests. | ||
|
||
## Requesting Session Signatures | ||
|
||
The Lit SDK has multiple methods for generating Session Signatures: | ||
|
||
- [`getSessionSigs`](../../sdk/authentication/session-sigs/get-session-sigs) | ||
- This function is the simplest way to get Session Signatures, at the minimum only requiring an Ethereum wallet and the `LitNodeClient`. It will enable specific capabilities for your session keypair using the resources you specify in the `AuthSig`. | ||
- [`getPkpSessionSigs`](../../sdk/authentication/session-sigs/get-pkp-session-sigs) | ||
- This function uses the [signSessionKey](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#signSessionKey) function to sign the session public key using the PKP, which will generate an `AuthSig`. Once the `AuthSig` has been created, it is then signed by the session keypair. Signing the `AuthSig` with the session keypair creates the Session Signatures. | ||
- [`getLitActionSessionSigs`](../../sdk/authentication/session-sigs/get-lit-action-session-sigs) | ||
- This function is the same as `getPkpSessionSigs`, but executes the given Lit Action to determine authorization. | ||
|
||
The best method to use depends on your use case. | ||
|
||
### Storing Session Signatures | ||
|
||
#### Node.js | ||
|
||
If you're using Node.js, the Session Signatures will be stored wherever the [storageProvider](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.LitNodeClientConfig.html#storageProvider) is configured to store them. If no `storageProvider` is provided, the Session Signatures will not be stored. | ||
|
||
#### Browser | ||
|
||
If you're executing within a browser environment, the Session Signatures will be stored in the browser's local storage. To clear the cached Session Keypair, you can use the `disconnectWeb3` function (imported from the `@lit-protocol/auth-browser` package) as covered [here](./connecting-to-lit#browser-environment). | ||
|
||
### Session Capabilities | ||
|
||
Session Signatures are used to grant access to specific resources on the Lit network. The resources you can request for your session can be found [here](https://v6-api-doc-lit-js-sdk.vercel.app/enums/types_src.LitAbility.html). | ||
|
||
### Table | ||
|
||
| Resource | Requires Session Signatures | | ||
| ------------------------------- | --------------------------- | | ||
| Lit Action Execution | ✅ | | ||
| Minting a PKP | ❌ | | ||
| PKP Signing | ✅ | | ||
| Encryption Access Control | ❌ | | ||
| Decryption Access Control | ✅ | | ||
| Signing Access Control | ✅ | | ||
| Capacity Credits Authentication | ✅ | | ||
|
||
More information on the requestable resources can be found [here](https://v6-api-doc-lit-js-sdk.vercel.app/enums/types_src.LitAbility.html#AccessControlConditionSigning). | ||
|
||
### Restricting Session Signatures | ||
|
||
To restrict the usage of Session Signatures and define the length of their validity, you can use the `expiration` parameter. This parameter is a string that represents the ISO 8601 date and time when the Session Signatures will expire. Having the Session Signatures expire in 10 minutes would look like: | ||
|
||
```tsx | ||
expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; | ||
|
||
# Installing the SDK | ||
|
||
The `@lit-protocol/lit-node-client` package forms the core of the Lit SDK, providing essential functionality for both Node.js and browser environments. This page guides you through its installation process. | ||
|
||
## Installation with npm or Yarn | ||
<Tabs | ||
defaultValue="npm" | ||
values={[ | ||
{label: 'npm', value: 'npm'}, | ||
{label: 'yarn', value: 'yarn'}, | ||
]}> | ||
<TabItem value="npm"> | ||
|
||
```bash | ||
npm install @lit-protocol/lit-node-client | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="yarn"> | ||
|
||
```bash | ||
yarn add @lit-protocol/lit-node-client | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
## Node.js | ||
The minimum required version of Node.js is **v19.9.0** because of the requirement for **crypto** support. | ||
|
||
## Browser | ||
Setting up the Lit SDK in a browser environment is very similar to using it in Node.js, but there are a few differences. One key difference is the need for polyfills. These may include the `buffer`, `crypto`, `vm`, and `stream` libraries, but exactly which ones you need depends on the framework you're using. To resolve these issues, an example of polyfilling for Vite can be found [here](https://github.com/LIT-Protocol/developer-guides-code/blob/master/starter-guides/browser/vite.config.ts). |
Oops, something went wrong.