diff --git a/docs/paying-for-lit/capacity-credit-intro.md b/docs/paying-for-lit/capacity-credit-intro.md new file mode 100644 index 00000000..ff17921b --- /dev/null +++ b/docs/paying-for-lit/capacity-credit-intro.md @@ -0,0 +1,14 @@ +# Capacity Credits + +Capacity Credits are how you pay for usage of the Lit network. They allow you to reserve a specific amount of capacity (i.e. requests a second) on the network over a pre-defined amount of time (e.g. one week). In order to make requests to the Lit network for things like: signing using a PKP, decrypting data, and executing a Lit Action. You'll need to provide the token ID of an active Capacity Credit along with your request. + +:::info +For an overview of what requests to the Lit network require payment, go [here](./overview.md#overview-of-what-requires-payment). +::: + +Capacity credits are NFT tokens on the [Chronicle Yellowstone](../connecting-to-a-lit-network/lit-blockchains/chronicle-yellowstone.md) rollup blockchain, and can be minted by making a transaction directly to the NFT contract, or by using the Lit Explorer. You can learn more about minting Capacity Credits via a specific method by going to these pages: + +- [Minting via the NFT contract](./minting-capacity-credit/via-contract.md) +- [Minting via the Lit Explorer](./minting-capacity-credit/via-explorer.md) + +After minting a Capacity Credit, you'll want to learn [how to delegate usage](./delegating-credit.md) of it to either your users, or yourself via a Capacity Delegation Auth Sig. diff --git a/docs/paying-for-lit/delegating-credit.md b/docs/paying-for-lit/delegating-credit.md new file mode 100644 index 00000000..625912d3 --- /dev/null +++ b/docs/paying-for-lit/delegating-credit.md @@ -0,0 +1,142 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Delegating a Credit + +To use a Capacity Credit to pay for usage of the Lit network, you need to create a *Capacity Delegation Auth Sig*. This Auth Sig is used as proof you have authorization to use a specific Capacity Credit to pay for requests to the Lit network like: signing using a PKP, decrypting data, and executing a Lit Action. + +:::info +To learn more about what a Capacity Credit is, and how they're used, please go [here](./capacity-credit-intro.md). + +For an overview of what requests to the Lit network require payment, go [here](./overview.md#overview-of-what-requires-payment). +::: + +As we'll see later in the guide, these Auth Sigs are scoped to specific addresses and will be used to delegate usage of the credit to both yourself and your users to pay for network usage. + +The following code will demonstrate how to produce the Capacity Delegation Auth Sig. + +:::info +The full implementation of the code used in this guide can be found [here](https://github.com/LIT-Protocol/developer-guides-code/blob/master/paying-for-lit/nodejs/src/delegateCapacityCredit.ts). +::: + +## Prerequisites + +Before continuing, you'll need to have minted a Capacity Credit. This can be done by following these guides: + +- [Minting via the NFT contract](./minting-capacity-credit/via-contract.md) +- [Minting via the Lit Explorer](./minting-capacity-credit/via-explorer.md) + +## Setup + +### Installing the Required Dependencies + +This guide makes use of the following packages and are required to use the following code. You can install the dependencies from NPM using NPM or Yarn: + + + + +```bash +npm install \ +@lit-protocol/constants \ +@lit-protocol/lit-node-client \ +ethers@v5 +``` + + + + + +```bash +yarn add \ +@lit-protocol/constants \ +@lit-protocol/lit-node-client \ +ethers@v5 +``` + + + + +### Instantiating an Ethers Signer + +```ts +import ethers from "ethers"; +import { LIT_RPC } from "@lit-protocol/constants"; + +const ethersSigner = new ethers.Wallet( + process.env.ETHEREUM_PRIVATE_KEY, + new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE) +); +``` + +:::note +The address corresponding to `process.env.ETHEREUM_PRIVATE_KEY` **needs** to be the owner of the Capacity Credit. This wallet will be used to produce a [ERC-5573 SIWE](https://eips.ethereum.org/EIPS/eip-5573) message that authorizes usage of the credit later in the guide. +::: + +### Instantiating a `LitNodeClient` Client + +```ts +import { LitNodeClient } from "@lit-protocol/lit-node-client"; +import { LitNetwork } from "@lit-protocol/constants"; + +litNodeClient = new LitNodeClient({ + litNetwork: LitNetwork.DatilTest, + debug: false, +}); +await litNodeClient.connect(); +``` + +You can learn more about the `@lit-protocol/lit-node-client` package and what is offers using the [API reference docs](https://v6-api-doc-lit-js-sdk.vercel.app/modules/lit_node_client_src.html). + +## Generating the Capacity Delegation Auth Sig + +```ts +const { capacityDelegationAuthSig } = + await litNodeClient.createCapacityDelegationAuthSig({ + dAppOwnerWallet: ethersSigner, + capacityTokenId, + delegateeAddresses: [delegateeAddress], + uses: "1", + expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes + }); +``` + +### Parameters + +#### `dAppOwnerWallet` + +This parameter is a [SignerLike](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.SignerLike.html) object (for this guide it's an instance of `ethers.Wallet`) that will be used to sign the ERC-5573 SIWE message that authorizes `delegateeAddresses` to use the Capacity Credit. The Ethereum address of the signer **must** own the Capacity Credit to delegate usage of it. + +#### `capacityTokenId` + +This parameter is the token ID of the Capacity Credit you're delegating usage of. + +#### `delegateeAddresses` + +This is an array of Ethereum address that you're authorizing usage of the Capacity Credit to. If you're trying to use the Capacity Credit to pay for your own network usage, you would add your address in this array. + +#### `uses` + +This parameter sets the total number of times the Auth Sig can be used to pay for network usage across all addresses listed in `delegateeAddresses`. Once the total `uses` is exhausted, the Auth Sig becomes invalid for payment by any delegated address. For example, if `uses` is set to `10` and one delegated address consumes all `10` uses, the Auth Sig can no longer be used for payment by any other delegated addresses. + +#### `expiration` + +This parameter sets a time limit, represented as a UTC timestamp in seconds, for the Auth Sig. It specifies when the Auth Sig will become invalid and can no longer be used. + +In the above code, this Auth Sig is being set to expire `10 minutes` after it's created. + +### Return Value + +Calling `litNodeClient.createCapacityDelegationAuthSig` will create a ERC-5573 SIWE message and sign it using `dAppOwnerWallet`. The object returned by this function contains the Capacity Delegation Auth Sig that can be used to pay for requests to the Lit network. + +## Summary + +:::info +The full implementation of the code used in this guide can be found [here](https://github.com/LIT-Protocol/developer-guides-code/blob/master/paying-for-lit/nodejs/src/delegateCapacityCredit.ts). +::: + +After running the above code, you will have created a Capacity Delegation Auth Sig that authorizes use of a specific Capacity Credit to a specific set of addresses with restrictions. For an example of using the Auth Sig, go [here](./using-delegated-auth-sig.md). diff --git a/docs/paying-for-lit/lit-relayer.md b/docs/paying-for-lit/lit-relayer.md new file mode 100644 index 00000000..6949a875 --- /dev/null +++ b/docs/paying-for-lit/lit-relayer.md @@ -0,0 +1,46 @@ +# Lit Relayer + +The Lit Relayer is an [open-source service](https://github.com/LIT-Protocol/relay-server) currently hosted by Lit to facilitate onboarding into the Lit ecosystem. It helps reduce initial costs by covering or subsidizing certain interactions with the Lit network, such as minting Programmable Key Pairs (PKPs). + +While the Relayer eases the onboarding process, it's important to note that its availability is not guaranteed. Users may experience rate limiting and/or congestion due to its shared nature. + +As your application moves into production, we recommend implementing this functionality directly into your own application instead of using the Lit Relayer. This will ensure that you can use the Lit network with minimal friction and disruptions in service, as your direct implementation will be much more reliable and scalable. + +## Overview of Lit Relayer Functions + +The Lit Relayer provides the following functions to help interact with the Lit network: + +### PKP Minting + +The Relayer can mint PKPs on behalf of users, subsidizing the minting costs. This process verifies the authenticity of various authentication methods, then associates the public key of a newly generated PKP with the authenticated identity. + +The currently supported authentication methods include: + + - WebAuthn + - Google OAuth + - Discord OAuth + - Stytch Otp + - Ethereum wallet signatures + - One-time passwords (OTP) + +The Relayer also supports retrieving all the PKPs associated with authenticated accounts. + +### Payment Delegation Database + +The Relayer also provides access to the [Payment Delegation Database](./payment-delegation-db.md), please refer to it's documentation to learn more. + +## Using the Lit Relayer + +To use the Lit Relayer, you must have a valid API key, as all communication with the Relayer is done using HTTP requests to the [Relayer endpoints](https://github.com/LIT-Protocol/relay-server?tab=readme-ov-file#available-endpoints). + +If you don't already have an API key, you can request one by filling out [this form](https://docs.google.com/forms/d/e/1FAIpQLSeVraHsp1evK_9j-8LpUBiEJWFn4G5VKjOWBmHFjxFRJZJdrg/viewform). + +## Limitations and Considerations + +While the Lit Relayer is a useful tool for getting started with Lit Protocol, there are some important considerations: + +1. **Rate Limiting**: To prevent abuse, the Relayer implements rate limiting. Your application may encounter usage limits. + +2. **Availability**: As a shared service, the Relayer may experience congestion or downtime. + +3. **Scalability**: For production applications, it's recommended to implement Relayer functionality directly in your application for better reliability and scalability. diff --git a/docs/paying-for-lit/minting-capacity-credit/assets/confirmation-notification.png b/docs/paying-for-lit/minting-capacity-credit/assets/confirmation-notification.png new file mode 100644 index 00000000..6755c766 Binary files /dev/null and b/docs/paying-for-lit/minting-capacity-credit/assets/confirmation-notification.png differ diff --git a/docs/paying-for-lit/minting-capacity-credit/assets/connecting-wallet.png b/docs/paying-for-lit/minting-capacity-credit/assets/connecting-wallet.png new file mode 100644 index 00000000..951c8c27 Binary files /dev/null and b/docs/paying-for-lit/minting-capacity-credit/assets/connecting-wallet.png differ diff --git a/docs/paying-for-lit/minting-capacity-credit/assets/lit-explorer.png b/docs/paying-for-lit/minting-capacity-credit/assets/lit-explorer.png new file mode 100644 index 00000000..ec9fc138 Binary files /dev/null and b/docs/paying-for-lit/minting-capacity-credit/assets/lit-explorer.png differ diff --git a/docs/paying-for-lit/minting-capacity-credit/assets/minting-credit.png b/docs/paying-for-lit/minting-capacity-credit/assets/minting-credit.png new file mode 100644 index 00000000..ae23f0b6 Binary files /dev/null and b/docs/paying-for-lit/minting-capacity-credit/assets/minting-credit.png differ diff --git a/docs/paying-for-lit/minting-capacity-credit/assets/profile.png b/docs/paying-for-lit/minting-capacity-credit/assets/profile.png new file mode 100644 index 00000000..c899135e Binary files /dev/null and b/docs/paying-for-lit/minting-capacity-credit/assets/profile.png differ diff --git a/docs/paying-for-lit/minting-capacity-credit/assets/selecting-datil-test.png b/docs/paying-for-lit/minting-capacity-credit/assets/selecting-datil-test.png new file mode 100644 index 00000000..05a2c60e Binary files /dev/null and b/docs/paying-for-lit/minting-capacity-credit/assets/selecting-datil-test.png differ diff --git a/docs/paying-for-lit/minting-capacity-credit/assets/sign-tx.png b/docs/paying-for-lit/minting-capacity-credit/assets/sign-tx.png new file mode 100644 index 00000000..f08efc2d Binary files /dev/null and b/docs/paying-for-lit/minting-capacity-credit/assets/sign-tx.png differ diff --git a/docs/paying-for-lit/minting-capacity-credit/via-contract.md b/docs/paying-for-lit/minting-capacity-credit/via-contract.md new file mode 100644 index 00000000..99a97ccf --- /dev/null +++ b/docs/paying-for-lit/minting-capacity-credit/via-contract.md @@ -0,0 +1,140 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Via the Lit Contracts SDK + +Capacity Credits can be minted by making requests to the NFT contract that is deployed on the [Chronicle Yellowstone](../../connecting-to-a-lit-network/lit-blockchains/chronicle-yellowstone.md) rollup blockchain. The following code will demonstrate how to connect to Chronicle Yellowstone via the Lit RPC URL, and send a transaction to the blockchain to mint a new Capacity Credit. + +:::info +To learn more about what a Capacity Credit is, and how they're used, please go [here](../capacity-credit-intro.md). + +The full implementation of the code used in this guide can be found [here](https://github.com/LIT-Protocol/developer-guides-code/blob/master/paying-for-lit/nodejs/src/mintCapacityCredit.ts). +::: + +## Prerequisites + +Before continuing, you'll need access to an Ethereum wallet that has [Lit test tokens](../../connecting-to-a-lit-network/lit-blockchains/chronicle-yellowstone.md#tstlpx-test-token) on the Chronicle Yellowstone blockchain. If you don't already have tokens, you can request some using [the faucet](https://chronicle-yellowstone-faucet.getlit.dev/). The `tstLPX` test token will be sent to your wallet address, allowing you to perform transactions on the rollup. + +## Setup + +### Installing the Required Dependencies + +This guide makes use of the following packages and are required to use the following code. You can install the dependencies from NPM using NPM or Yarn: + + + + +```bash +npm install \ +@lit-protocol/constants \ +@lit-protocol/contracts-sdk \ +ethers@v5 +``` + + + + + +```bash +yarn add \ +@lit-protocol/constants \ +@lit-protocol/contracts-sdk \ +ethers@v5 +``` + + + + +### Instantiating an Ethers Signer + +```ts +import ethers from "ethers"; +import { LIT_RPC } from "@lit-protocol/constants"; + +const ethersSigner = new ethers.Wallet( + process.env.ETHEREUM_PRIVATE_KEY, + new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE) +); +``` + +### Instantiating a `LitContracts` Client + +```ts +import { LitContracts } from "@lit-protocol/contracts-sdk"; +import { LitNetwork } from "@lit-protocol/constants"; + +const litContractClient = new LitContracts({ + signer: ethersSigner, + network: LitNetwork.DatilTest, +}); +await litContractClient.connect(); +``` + +You can learn more about the `@lit-protocol/contracts-sdk` package and what is offers using the [API reference docs](https://v6-api-doc-lit-js-sdk.vercel.app/modules/contracts_sdk_src.html). + +## Minting a Capacity Credit + +```ts +const capacityCreditInfo = await litContractClient.mintCapacityCreditsNFT({ + requestsPerKilosecond: 80, + // requestsPerDay: 14400, + // requestsPerSecond: 10, + daysUntilUTCMidnightExpiration: 1, +}); +``` + +### Parameters + +When minting a credit, the following parameters are required: + +#### `requestsPerX` + +This parameter is the capacity you're reserving on the Lit network. This value is the maximum number of requests your Capacity Credit can be used for in a given day. Once your credit has been used for this number of requests, you will receive a Rate Limit error if it's used again before midnight UTC time. + +For convenience, any one of the following properties can be used: + - `requestsPerKilosecond` + - `requestsPerDay` + - `requestsPerSecond` + +#### `daysUntilUTCMidnightExpiration` + +This parameter sets the date the Capacity Credit will expire. The credit expires at 12:00 AM (midnight) Coordinated Universal Time (UTC) on the specified date. + +:::note +The actual expiration time in your local timezone may be different due to the UTC conversion. For example, if you're in New York (ET), a credit set to expire on June 1st will actually expire on May 31st at 8:00 PM ET. +::: + +### Return Value + +Calling `litContractClient.mintCapacityCreditsNFT` will create and sign a transaction to the Chronicle Yellowstone blockchain, paying for both the Capacity Credit and transaction gas in the Lit test token. + +After the transaction is processed and included in a block, you will be returned the following Capacity Credit info: + +``` +{ + rliTxHash: string; + capacityTokenId: number; + capacityTokenIdStr: string; +} +``` + +Where: + +- `rliTxHash` Is the transaction hash of the transaction that minted the credit. +- `capacityTokenId` Is the generated ID for the new credit as a `number`. +- `capacityTokenIdStr` Is the generated ID for the new credit as a `string`. + +You will use either `capacityTokenId` or `capacityTokenIdStr` to identify the Capacity Credit you would like use when paying for request to the Lit network. + +## Summary + +:::info +The full implementation of the code used in this guide can be found [here](https://github.com/LIT-Protocol/developer-guides-code/blob/master/paying-for-lit/nodejs/src/mintCapacityCredit.ts). +::: + +After running the above code, you will have minted a new Capacity Credit that can be used to pay for usage of the Lit network. To learn more about how to use this credit for payment, please go [here](../delegating-credit.md). diff --git a/docs/paying-for-lit/minting-capacity-credit/via-explorer.md b/docs/paying-for-lit/minting-capacity-credit/via-explorer.md new file mode 100644 index 00000000..c7d71896 --- /dev/null +++ b/docs/paying-for-lit/minting-capacity-credit/via-explorer.md @@ -0,0 +1,92 @@ +# Via the Lit Explorer + +Capacity Credits can be minted using the [Lit Explorer](https://explorer.litprotocol.com/) dApp. The following guide will demonstrate how to mint a new Capacity Credit. + +:::info +To learn more about what a Capacity Credit is, and how they're used, please go [here](../capacity-credit-intro.md). +::: + +## Prerequisites + +Before continuing, you'll need access to an Ethereum wallet that has [Lit test tokens](../../connecting-to-a-lit-network/lit-blockchains/chronicle-yellowstone.md#tstlpx-test-token) on the Chronicle Yellowstone blockchain. If you don't already have tokens, you can request some using [the faucet](https://chronicle-yellowstone-faucet.getlit.dev/). The `tstLPX` test token will be sent to your wallet address, allowing you to perform transactions on the rollup. + +You'll also need to add the Chronicle Yellowstone [chain facts](../../connecting-to-a-lit-network/lit-blockchains/chronicle-yellowstone.md#connecting-to-chronicle-yellowstone) to your wallet, so that you can send transaction to the network. + +## Setup + +1. Navigate to the [Lit Explorer](https://explorer.litprotocol.com/) dApp. + +![The Lit Explorer](assets/lit-explorer.png) + +2. Connect your wallet to the explorer by clicking the `Connect Wallet` button. + +![Connecting Wallet](assets/connecting-wallet.png) + +3. Select the Lit network you'd like to mint the Capacity Credit for. + +This is done using the network dropdown next to the previously clicked `Connect Wallet` button. By default, the `Datil` network is selected - the Datil network is the decentralized mainnet beta Lit network. For an overview of the available Lit networks, go [here](../../connecting-to-a-lit-network/connecting.md). + +For this guide, we're going to select the `DatilTest` network: + +![Selecting Network](assets/selecting-datil-test.png) + +## Minting a Capacity Credit + +The following UI is how we'll mint a new Capacity Credit: + +![Minting Credit](assets/minting-credit.png) + +### Requests Per Kilosecond + +This parameter is the capacity you're reserving on the Lit network measured in requests per kilosecond. This value is the maximum number of requests your Capacity Credit can be used for in a given day. Once your credit has been used for this number of requests, you will receive a Rate Limit error if it's used again before midnight UTC time. + +For convenience, the number inputted is converted to the number of requests per day. By default, this value is set to `14` requests per kilosecond which is also `1,204` request per day. + +### UTC Midnight Expiration Date + +This parameter sets the date the Capacity Credit will expire. The credit expires at 12:00 AM (midnight) Coordinated Universal Time (UTC) on the specified date. + +:::note +The actual expiration time in your local timezone may be different due to the UTC conversion. For example, if you're in New York (ET), a credit set to expire on June 1st will actually expire on May 31st at 8:00 PM ET. +::: + +### Estimated Cost + +This is the estimated cost, in Lit test tokens, to mint the Capacity Credit with the parameters you have selected. + +:::note +Important considerations: + +- The estimated cost does not include the gas fee for the transaction. +- The actual cost may fluctuate depending on network usage: + - It may increase as more users reserve network capacity. + - It may decrease as previously reserved network capacity expires. +::: + +### Buying the Credit + +After selecting your credit parameters, click the `Buy Capacity Credits` button to create the transaction to the Chronicle Yellowstone blockchain to purchase your credit. + +You should be prompted by your Ethereum wallet to sign and submit the transaction to the blockchain: + +![Sign Tx](assets/sign-tx.png) + +After signing and submitting the transaction to the network, you will receive a confirmation notification similar to: + +![Confirmation Notification](assets/confirmation-notification.png) + +You can click the transaction hash in the notification to be taken to the Lit block explorer to view the transaction details. + +### Getting the Credit Info + +In order to use your new Capacity Credit to pay for the usage of the Lit network, you need to know the *Token ID* of the credit. You find this for the new credit, as well as all other credits minted by your account, by navigating the the [Profile](https://explorer.litprotocol.com/profile) page. + +On this page you will see all of the PKPs and RLI (Capacity Credit) tokens that are associated with your account. + +![Profile](assets/profile.png) + +In the `Your RLI Tokens` table, you will see the info for the Capacity Credit you just minted. The `Token ID` (in the screenshot that's `751`) is the identifier for your credit, and the value you will use when when making requests to the Lit network. + +## Summary + +After following the above guide, you will have minted a new Capacity Credit that can be used to pay for usage of the Lit network. To learn more about how to use this credit for payment, please go [here](../delegating-credit.md). \ No newline at end of file diff --git a/docs/paying-for-lit/overview.md b/docs/paying-for-lit/overview.md new file mode 100644 index 00000000..4284fb38 --- /dev/null +++ b/docs/paying-for-lit/overview.md @@ -0,0 +1,120 @@ +# Paying for the Usage of the Lit Network + +Like other decentralized networks, Lit has a certain amount of computation available for users that's metered to allow for a responsive network with nodes that are able to stay in-sync with one another. + +In order to use the decentralized testnet ([Datil-test](../connecting-to-a-lit-network/testnets#datil-test)) and production-ready mainnet beta ([Datil](../connecting-to-a-lit-network/mainnets#datil)) Lit networks, you will need to pay for usage of the network. This is done using Lit test tokens, Capacity Credits, the Lit Relayer, and the Payment Delegation Database. + +## Overview of What Requires Payment + +:::note +Currently requests requiring payment of Lit tokens is done only using the `testLPX` test token. More information about the test token is available [here](../connecting-to-a-lit-network/lit-blockchains/chronicle-yellowstone.md#tstlpx-test-token) +::: + +### General Lit Network Usage + +| Request Type | Requires Payment | Can Be Paid for Using the Lit Relayer | Payment Type | Requires Gas | +|---------------------------------------------|------------------|----------------------------------|------------------|--------------| +| Connecting to a Lit Network | ❌ | n/a | n/a | ❌ | +| Generating Session Signatures | ❌ | n/a | n/a | ❌ | +| Reading Data from Lit Contracts | ❌ | n/a | n/a | ❌ | +| Lit Action Execution | ✅ | ❌ | Capacity Credits | ❌ | +| Setting Up a Payment Delegation Payer | ✅ | ✅ | Lit Test Tokens | ✅ | +| Adding / Removing Payment Delegation Payees | ✅ | ✅ | Lit Test Tokens | ✅ | + +### Capacity Credits + +| Request Type | Requires Payment | Can Be Paid for Using the Lit Relayer | Payment Type | Requires Gas | +|---------------------|------------------|----------------------------------|-----------------|--------------| +| Minting a Credit | ✅ | ❌ | Lit Test Tokens | ✅ | +| Delegating a Credit | ❌ | n/a | n/a | ❌ | + +### PKP Usage + +| Request Type | Requires Payment | Can Be Paid for Using the Lit Relayer | Payment Type | Requires Gas | +|------------------------------------|------------------|----------------------------------|------------------|--------------| +| Minting a PKP | ✅ | ✅ | Lit Test Tokens | ✅ | +| Adding / Removing PKP Auth Methods | ✅ | ✅ | Lit Test Tokens | ✅ | +| Signing with a PKP | ✅ | ❌ | Capacity Credits | ❌ | + +### Encrypting Data + +| Request Type | Requires Payment | Can Be Paid for Using the Lit Relayer | Payment Type | Requires Gas | +|-----------------|------------------|----------------------------------|------------------|--------------| +| Encrypting Data | ❌ | n/a | n/a | ❌ | +| Decrypting Data | ✅ | ❌ | Capacity Credits | ❌ | + +### Wrapped Keys Usage + +| Request Type | Requires Payment | Can Be Paid for Using the Lit Relayer | Payment Type | Requires Gas | +|----------------------------------------|------------------|----------------------------------|--------------------------------------|--------------| +| Generating a Wrapped Key | ✅ | ❌ | Lit Test Tokens | ✅ | +| Importing Wrapped Key | ❌ | n/a | n/a | ❌ | +| Exporting Wrapped Key | ✅ | ❌ | Capacity Credits | ❌ | +| Getting Wrapped Key Metadata | ✅ | ❌ | Capacity Credits | ❌ | +| Storing Wrapped Key Metadata | ❌ | n/a | n/a | ❌ | +| Listing Wrapped Keys for a PKP | ❌ | n/a | n/a | ❌ | +| Signing a Message with Wrapped Key | ✅ | ❌ | Capacity Credits | ❌ | +| Signing a transaction with Wrapped Key | ✅ | ❌ | Capacity Credits | ❌ | +| Custom Wrapped Keys | ✅ | ❌ | Lit Test Tokens and Capacity Credits | ✅ | + + +## Overview of Payment Methods + +### Lit Test Token + +Currently the [`testLPX` test token](../connecting-to-a-lit-network/lit-blockchains/chronicle-yellowstone.md#tstlpx-test-token) is the native currency for the Lit [Chronicle Yellowstone](../connecting-to-a-lit-network/lit-blockchains/chronicle-yellowstone.md) rollup blockchain. It's currently used to pay for the gas of on-chain transactions, as well as for minting PKPs and Capacity Credits. + +To obtain the `tstLPX` test token, please use [the faucet](https://chronicle-yellowstone-faucet.getlit.dev/). The `tstLPX` test token will be sent to your wallet address, allowing you to perform transactions on the rollup. + +### Capacity Credits + +Capacity Credits are NFT tokens that represent reserved computational capacity on the Lit network. When minting a credit, you specify and pay to reserve a specific amount of requests per second over a period of time. You'll then use these credits when making requests to the Lit network to perform actions such as decryption, executing Lit Actions, and signing transactions using PKPs and Wrapped Keys. + +For a deep dive into Capacity Credits, including minting and usage details, checkout the in-depth [documentation](./capacity-credit-intro.md). + +### Lit Relayer + +The Lit Relayer is an [open-source service](https://github.com/LIT-Protocol/relay-server) currently hosted by Lit to facilitate onboarding into the Lit ecosystem. It helps reduce initial costs by covering or subsidizing certain interactions with the Lit network, such as minting PKPs and paying for network requests to perform actions like decryption, executing Lit Actions, and using PKPs. + +While the Relayer eases the onboarding process, it's important to note that its availability is not guaranteed. Users may experience rate limiting and/or congestion due to its shared nature. + +As your application moves into production, we recommend implementing this functionality directly into your own application instead of using the Lit Relayer. This will ensure that you can use the Lit network with minimal friction and disruptions in service, as your direct implementation will be much more reliable and scalable. + +For a deep dive into the Relayer, including its usage and offered services, checkout the in-depth [documentation](./lit-relayer.md). + +### Payment Delegation Database + +The Payment Delegation Database is a service provided by the Lit Relayer that streamlines payment management for your users. This service offers an alternative to relying on the Lit Relayer's payment subsidies or minting individual Capacity Credits for each of your users. With the Payment Delegation Database, you can establish a Payer Wallet and designate your users as Payees. + +The Payer Wallet acts as a central account that manages payment for Lit network usage on behalf of your users (Payees). Payees inherit the reserved capacity of the Payer Wallet, which automatically receives a minted capacity credit when registered with the service. + +For a deep dive into the Payment Delegation Database, including how to register a Payer Wallet and add users as Payees, checkout the in-depth [documentation](./payment-delegation-db.md). + +### Choosing the Right Payment Method + +The Lit network offers various ways to implement payment for usage of the network, suiting various use cases and application scales. Consider the following guidelines when selecting the most appropriate option for your needs: + +- Capacity Credits: Ideal for individual users or small-scale applications requiring direct control over their network resource allocation. This option is ideal when you don't have to manage payments for a large user base. +- Lit Relayer: Best for initial testing and prototyping. It reduces onboarding friction by subsidizing some network interactions, but is subject to availability and potential rate limiting. +- Payment Delegation Database: Suitable for larger applications or those with a large user base. It simplifies and centralizes the minting and delegation of Capacity Credits to your users, eliminating the need to manage individual Capacity Credits for each user. + +For optimal results: + +- New developers may start with the Lit Relayer managing Capacity Credit on their behalf for easier onboarding. +- As your application grows, transition to managing Capacity Credits yourself for more reliable resource allocation. +- Large-scale applications should consider the Payment Delegation Database for managing payment on behalf of many users. + +## Getting Started + +To begin using the paid Lit networks: + +1. Assess your needs: Consider your expected usage, scale of operations, and whether you'll be managing payments for multiple users. +2. Choose a payment method: + - For testing and prototyping, start with the Lit Relayer managing Capacity Credits. + - For individual or small-scale use, consider managing Capacity Credits yourself. + - For applications with many users, look into the Payment Delegation Database. +3. Set up your chosen method: + - For the Lit Relayer, go [here](./lit-relayer.md) to begin integrating it into your application. + - For Capacity Credits, go [here](./capacity-credit-intro.md) to learn how to mint and use them. + - For the Payment Delegation Database, go [here](./payment-delegation-db.md) to learn how to register a Payer Wallet and add your users as Payees. +4. Monitor your usage and adjust as needed. diff --git a/docs/sdk/paying-for-lit/payment-delegation-db.md b/docs/paying-for-lit/payment-delegation-db.md similarity index 99% rename from docs/sdk/paying-for-lit/payment-delegation-db.md rename to docs/paying-for-lit/payment-delegation-db.md index 63739ebc..c47917b2 100644 --- a/docs/sdk/paying-for-lit/payment-delegation-db.md +++ b/docs/paying-for-lit/payment-delegation-db.md @@ -2,7 +2,7 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FeedbackComponent from "@site/src/pages/feedback.md"; -# Paying for Users Via The Lit Relayer +# Payment Delegation Database ## Paying for Lit diff --git a/docs/paying-for-lit/using-delegated-auth-sig.md b/docs/paying-for-lit/using-delegated-auth-sig.md new file mode 100644 index 00000000..1b46238b --- /dev/null +++ b/docs/paying-for-lit/using-delegated-auth-sig.md @@ -0,0 +1,162 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Using a Delegation Auth Sig to Make Requests + +When making requests to the Lit network, you must provide [Session Signatures](../sdk/authentication/session-sigs/intro.md). When making requests to the network that require payment, you must also attach a *Capacity Delegation Auth Signature* to your Session Signatures. This Auth Sig tells the Lit network which Capacity Credit to use for paying for your network usage, and also acts as proof that you have permission to use the Capacity Credit for payment. + +:::info +To learn more about what a Capacity Credit is, and how they're used, go [here](./capacity-credit-intro.md). + +To learn about how to obtain a Capacity Delegation Auth Signature, go [here](./delegating-credit.md). + +For an overview of what requests to the Lit network require payment, go [here](./overview.md#overview-of-what-requires-payment). +::: + +The following code will demonstrate executing a Lit Action, one of the types of requests that requires payment, using Session Signatures that contain a Capacity Delegation Auth Signature. + +:::info +The full implementation of the code used in this guide can be found [here](https://github.com/LIT-Protocol/developer-guides-code/blob/master/paying-for-lit/nodejs/src/getSessionSigsWithCapacityCreditAuthSig.ts). +::: + +## Prerequisites + +Before continuing, you should have an understanding of: + +- [How to obtain a Capacity Delegation Auth Signature](./delegating-credit.md) +- [How to generate Session Signatures](../sdk/authentication/session-sigs/get-session-sigs.md) +- How to execute a [Lit Action](../sdk/serverless-signing/overview) + +## Setup + +### Installing the Required Dependencies + +This guide makes use of the following packages and are required to use the following code. You can install the dependencies from NPM using NPM or Yarn: + + + + +```bash +npm install \ +@lit-protocol/constants \ +@lit-protocol/lit-node-client \ +@lit-protocol/auth-helpers \ +ethers@v5 +``` + + + + + +```bash +yarn add \ +@lit-protocol/constants \ +@lit-protocol/lit-node-client \ +@lit-protocol/auth-helpers \ +ethers@v5 +``` + + + + +### Instantiating an Ethers Signer + +```ts +import ethers from "ethers"; +import { LIT_RPC } from "@lit-protocol/constants"; + +const ethersSigner = new ethers.Wallet( + process.env.ETHEREUM_PRIVATE_KEY, + new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE) +); +``` + +:::note +The address corresponding to `process.env.ETHEREUM_PRIVATE_KEY` **needs** to have been included in the `delegateeAddresses` for the Capacity Delegation Auth Signature used in this guide. +::: + +### Instantiating a `LitNodeClient` Client + +```ts +import { LitNodeClient } from "@lit-protocol/lit-node-client"; +import { LitNetwork } from "@lit-protocol/constants"; + +litNodeClient = new LitNodeClient({ + litNetwork: LitNetwork.DatilTest, + debug: false, +}); +await litNodeClient.connect(); +``` + +You can learn more about the `@lit-protocol/lit-node-client` package and what is offers using the [API reference docs](https://v6-api-doc-lit-js-sdk.vercel.app/modules/lit_node_client_src.html). + +### Generating Session Sigs with the Delegation Auth Sig + +:::info +For more information on how the `getSessionSigs` works and it's parameters, please go [here](../sdk/authentication/session-sigs/get-session-sigs.md). +::: + +```ts +const sessionSigs = await litNodeClient.getSessionSigs({ + chain: "ethereum", + expiration: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(), // 24 hours + capabilityAuthSigs: [capacityDelegationAuthSig], + resourceAbilityRequests: [ + { + resource: new LitActionResource("*"), + ability: LitAbility.LitActionExecution, + }, + ], + authNeededCallback: async ({ + resourceAbilityRequests, + expiration, + uri, + }) => { + const toSign = await createSiweMessageWithRecaps({ + uri: uri!, + expiration: expiration!, + resources: resourceAbilityRequests!, + walletAddress: ethersSigner.address, + nonce: await litNodeClient.getLatestBlockhash(), + litNodeClient, + }); + + return await generateAuthSig({ + signer: ethersSigner, + toSign, + }); + }, +}); +``` + +This line from the above code is how we're specifying the Capacity Delegation Auth Signature (that's delegating credit usage to `ethersSigner.address`) to pay for our request later in this guide: + +```ts +capabilityAuthSigs: [capacityDelegationAuthSig] +``` + +## Making a Request + +After executing the above code, you will now have Session Signatures that contain a Capacity Delegation Auth Signature. These Session Signatures can be used to make any requests to the Lit network that require payment. + +Here is an example of using the Session Signatures to execute a simple Lit Action: + +```ts +await litNodeClient.executeJs({ + sessionSigs, + code: `(() => console.log("It works!"))();`, +}); +``` + +## Summary + +:::info +The full implementation of the code used in this guide can be found [here](https://github.com/LIT-Protocol/developer-guides-code/blob/master/paying-for-lit/nodejs/src/getSessionSigsWithCapacityCreditAuthSig.ts). +::: + +This guide has demonstrated how to use a Capacity Delegation Auth Signature to generate Session Signatures, and use those Session Signature to make a request to the Lit network that requires payment. diff --git a/sidebars.js b/sidebars.js index 4d4cf3d3..1679262c 100644 --- a/sidebars.js +++ b/sidebars.js @@ -112,6 +112,41 @@ const sidebars = { }, ], }, + { + type: 'category', + label: 'Paying for Usage of Lit', + collapsed: true, + link: { + type: 'doc', + id: 'paying-for-lit/overview', + }, + items: [ + { + type: 'category', + label: 'Capacity Credits', + collapsed: true, + link: { + type: 'doc', + id: 'paying-for-lit/capacity-credit-intro', + }, + items: [ + { + type: 'category', + label: 'Minting a Capacity Credit', + collapsed: true, + items: [ + 'paying-for-lit/minting-capacity-credit/via-contract', + 'paying-for-lit/minting-capacity-credit/via-explorer', + ], + }, + 'paying-for-lit/delegating-credit', + 'paying-for-lit/using-delegated-auth-sig', + ], + }, + 'paying-for-lit/lit-relayer', + 'paying-for-lit/payment-delegation-db', + ], + }, { type: 'category', label: 'Guides', @@ -123,12 +158,6 @@ const sidebars = { keywords: ['guides'], }, items: [ - { - type: 'category', - label: 'Paying for Lit', - collapsed: true, - items: ['sdk/paying-for-lit/payment-delegation-db'], - }, { type: 'category', label: 'Authentication',