diff --git a/docs/api-reference/latest.md b/docs/api-reference/latest.md index ee90d6d8..e0435d8f 100644 --- a/docs/api-reference/latest.md +++ b/docs/api-reference/latest.md @@ -2,6 +2,6 @@ import FeedbackComponent from "@site/src/pages/feedback.md"; # Latest SDK Version -The most recent version of the SDK i.e. v6.x.x (beta) API docs can be viewed [here](https://v6-api-doc-lit-js-sdk.vercel.app/). +The most recent version of the SDK (v7.x.x) API docs can be viewed [here](https://v7-api-doc-lit-js-sdk.vercel.app/). diff --git a/docs/api-reference/v6-sdk.md b/docs/api-reference/v6-sdk.md new file mode 100644 index 00000000..ddf04d8d --- /dev/null +++ b/docs/api-reference/v6-sdk.md @@ -0,0 +1,9 @@ + +# SDK 6.x.x + +The SDK v6.x.x API docs can be viewed [here](https://v6-api-doc-lit-js-sdk.vercel.app/). + +:::warning +Please note that the latest API docs are [here](https://developer.litprotocol.com/api-reference/latest/). +::: + diff --git a/docs/concepts/capacity-credits-concept.md b/docs/concepts/capacity-credits-concept.md index 3c0ea97c..38b459e3 100644 --- a/docs/concepts/capacity-credits-concept.md +++ b/docs/concepts/capacity-credits-concept.md @@ -47,10 +47,10 @@ You can read more about Session Signatures [here](../sdk/authentication/session- ```javascript -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK, LIT_ABILITY } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.DatilTest, checkNodeAttestation: true, }); @@ -66,12 +66,12 @@ import { LitNetwork } from "@lit-protocol/constants"; recapObject.addCapabilityForResource( litResource, - LitAbility.LitActionExecution + LIT_ABILITY.LitActionExecution ); const verified = recapObject.verifyCapabilitiesForResource( litResource, - LitAbility.LitActionExecution + LIT_ABILITY.LitActionExecution ); if (!verified) { @@ -110,7 +110,7 @@ import { LitNetwork } from "@lit-protocol/constants"; resourceAbilityRequests: [ { resource: new LitActionResource('*'), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], authNeededCallback, diff --git a/docs/connecting-to-a-lit-network/connecting.md b/docs/connecting-to-a-lit-network/connecting.md index 1169c477..7cc3b174 100644 --- a/docs/connecting-to-a-lit-network/connecting.md +++ b/docs/connecting-to-a-lit-network/connecting.md @@ -1,14 +1,14 @@ # Connecting to a Lit Network -After installing the Lit SDK, you can connect an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) to a Lit network. This is done by setting the `litNetwork` property when instantiating an instance of `LitNodeClient`: +After installing the Lit SDK, you can connect an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) to a Lit network. This is done by setting the `litNetwork` property when instantiating an instance of `LitNodeClient`: ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ // Change this to the Lit SDK Network Identifier you want to connect to - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, }); await litNodeClient.connect(); ``` diff --git a/docs/integrations/aa/candide.md b/docs/integrations/aa/candide.md index b12aab06..20fd512c 100644 --- a/docs/integrations/aa/candide.md +++ b/docs/integrations/aa/candide.md @@ -49,37 +49,31 @@ JSON_RPC_NODE_PROVIDER= // Get an RPC from a Node provider #### Initialize the Lit Network Connection and GoogleProvider - Connect to the Lit Network using LitNodeClient. -- Set up the LitAuthClient for authentication. +- Set up the LitRelay for authentication. - Initialize a GoogleProvider for Google sign-in. ```jsx import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitAuthClient, GoogleProvider } from "@lit-protocol/lit-auth-client"; -import { ProviderType, LitNetwork } from "@lit-protocol/constants"; +import { LitRelay } from "@lit-protocol/lit-auth-client"; +import { GoogleProvider } from "@lit-protocol/providers"; +import { PROVIDER_TYPE, LIT_NETWORK } from "@lit-protocol/constants"; const initalizeClientsAndProvider = async () => { const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: true, }); await litNodeClient.connect(); - const litAuthClient = new LitAuthClient({ - litRelayConfig: { - relayApiKey: process.env.LIT_API_KEY, - }, - litNodeClient, + const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); + console.log("Connected to Lit Nodes and Lit Relay ✔️"); - console.log("Connected to Lit Node and Lit Auth Clients ✔️"); + const provider = new GoogleProvider({ relay: litRelay, litNodeClient }); - const provider = litAuthClient.initProvider( - ProviderType.Google, - { - // redirectUri: The redirect URI Lit's login server should redirect to after a successful login - } - ); - return { litNodeClient, litAuthClient, provider }; + return { litNodeClient, litRelay, provider }; }; ``` @@ -108,11 +102,20 @@ const authMethod = await generateAuthMethod(); if (!authMethod) { return; } -Mint PKP (Programmable Key Pair) -import { LitAuthClient } from "@lit-protocol/lit-auth-client"; +``` + +#### Mint PKP (Programmable Key Pair) + +```jsx +import { LitRelay } from "@lit-protocol/lit-auth-client"; const mintWithGoogle = async (authMethod) => { - const pkp = await litAuthClient.mintPKPWithAuthMethods([authMethod], { + const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', + }); + + const pkp = await litRelay.mintPKPWithAuthMethods([authMethod], { addPkpEthAddressAsPermittedAddress: true }); console.log("Fetched PKP", pkp); @@ -127,7 +130,7 @@ console.log("Minted PKP ✔️"); ```jsx import { PKPEthersWallet } from "@lit-protocol/pkp-ethers"; -import { LitAbility, LitPKPResource } from "@lit-protocol/auth-helpers"; +import { LIT_ABILITY, LitPKPResource } from "@lit-protocol/auth-helpers"; import { AuthCallbackParams } from "@lit-protocol/types"; import { LIT_RPC } from "@lit-protocol/constants"; @@ -139,7 +142,7 @@ const response = await litNodeClient.signSessionKey({ resourceAbilityRequests: [ { resource: new LitPKPResource("*"), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ], expiration: params.expiration, @@ -159,7 +162,7 @@ const guardianSigner = new PKPEthersWallet({ resourceAbilityRequests: [ { resource: new LitPKPResource("*"), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ], authNeededCallback: authNeededCallback, diff --git a/docs/integrations/aa/pimlico.md b/docs/integrations/aa/pimlico.md index 25ceb8b3..82919d6c 100644 --- a/docs/integrations/aa/pimlico.md +++ b/docs/integrations/aa/pimlico.md @@ -152,31 +152,37 @@ You can also ping the Lit developement team on [Discord](https://litgateway.com/ ### 6. Mint a PKPs through Lit Protocol ```js -const litClient = new LitAuthClient({ - litRelayConfig: { - relayApiKey: '', - } +import { LIT_NETWORK } from "@lit-protocol/constants"; +import { StytchOtpProvider } from "@lit-protocol/providers"; +import { LitRelay } from "@lit-protocol/lit-auth-client"; + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); - -const session = litClient.initProvider(ProviderType.StytchOtp, { + +const session = new StytchOtpProvider({ relay: litRelay, litNodeClient, userId: sessionStatus.session.user_id, appId: "project-test-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" -}) +}); const authMethod = await session.authenticate({ accessToken: sessionStatus.session_jwt -}) +}); -await session.mintPKPThroughRelayer(authMethod) -const pkps = await session.fetchPKPsThroughRelayer(authMethod) +await litRelay.mintPKPWithAuthMethods([authMethod], {}); +const pkps = await session.fetchPKPs(authMethod); ``` ### 7. Generate the Controller Session Signatures or its context to generate them on demand ```js +import { LitNodeClientNodeJs } from "@lit-protocol/lit-node-client-nodejs"; +import { LIT_ABILITY, LIT_NETWORK } from "@lit-protocol/constants"; + const litNodeClient = new LitNodeClientNodeJs({ - litNetwork: "datil-dev", + litNetwork: LIT_NETWORK.DatilDev, debug: false, }) await litNodeClient.connect(); @@ -184,7 +190,7 @@ await litNodeClient.connect(); const resourceAbilities = [ { resource: new LitActionResource("*"), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ]; @@ -228,8 +234,22 @@ We will now generate a wallet that can act a regular Ethers.js wallet, but will const pkpWallet = new PKPEthersWallet({ pkpPubKey: pkp[pkp.length - 1].publicKey, rpc: "", // e.g. https://rpc.ankr.com/eth_goerli + litNodeClient, + authContext: { + getSessionSigsProps: { + chain: 'ethereum', + expiration: new Date(Date.now() + 60_000 * 60).toISOString(), + resourceAbilityRequests: resourceAbilities, + authNeededCallback, + }, + }, + // controllerSessionSigs: sesionSigs, // (deprecated) If you will be passing sessionSigs directly, do not pass authContext +}); + +const pkpWallet = new PKPEthersWallet({ + pkpPubKey: pkp[pkp.length - 1].publicKey, + litNodeClient, authContext: { - client: litNodeClient, getSessionSigsProps: { chain: 'ethereum', expiration: new Date(Date.now() + 60_000 * 60).toISOString(), diff --git a/docs/integrations/storage/irys.md b/docs/integrations/storage/irys.md index 304acc5b..a4722f40 100644 --- a/docs/integrations/storage/irys.md +++ b/docs/integrations/storage/irys.md @@ -91,7 +91,7 @@ Connect to a Lit node on one of our [active networks](https://developer.litproto ```ts import * as LitJsSdk from "@lit-protocol/lit-node-client-nodejs"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; let litNodeClientInstance: LitJsSdk.LitNodeClientNodeJs | null = null; @@ -100,7 +100,7 @@ async function getLitNodeClient(): Promise { litNodeClientInstance = new LitJsSdk.LitNodeClientNodeJs({ alertWhenUnauthorized: false, - litNetwork: LitNetwork.DatilDev, // DatilDev network for free usage + litNetwork: LIT_NETWORK.DatilDev, // DatilDev network for free usage debug: false, }); @@ -181,8 +181,6 @@ We provide multiple methods to encrypt data, including strings, files, zip files - `encryptString():` Encrypts a string. - `encryptToJson()`: Encrypts a string or file and serializes the result to JSON. -- `zipAndEncryptString()`: Encrypts and compresses a string into a zip file. Useful for bundling multiple pieces of data. -- `encryptFile()` and `zipAndEncryptFiles()`: Encrypt a single file or multiple files. We will use `encryptString()` to encrypt a simple string: @@ -291,7 +289,7 @@ async function decryptData( resourceAbilityRequests: [ { resource: new LitAccessControlConditionResource("*"), - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback: async (params: any) => { @@ -351,10 +349,13 @@ Connect to a Lit node on one of our [active networks](https://developer.litproto ```ts import * as LitJsSdk from "@lit-protocol/lit-node-client"; import { LitNodeClient } from "@lit-protocol/lit-node-client"; +import { LIT_NETWORK } from "@lit-protocol/constants"; -const litClient = new LitNodeClient({ - litNetwork: "datil-dev", +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, }); + +await litNodeClient.connect(); ``` ### Setting Access Control Rules @@ -427,8 +428,6 @@ We provide multiple methods to encrypt data, including strings, files, zip files - `encryptString()`: Encrypts a string. - `encryptToJson()`: Encrypts a string or file and serializes the result to JSON. -- `zipAndEncryptString()`: Encrypts and compresses a string into a zip file. Useful for bundling multiple pieces of data. -- `encryptFile()` and `zipAndEncryptFiles()`: Encrypt a single file or multiple files. We will use `encryptString()` to encrypt a string: @@ -569,7 +568,7 @@ export const decryptData = async (encryptedText: string, dataToEncryptHash: stri resourceAbilityRequests: [ { resource: litResource, - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback, diff --git a/docs/intro/first-request/connecting-to-lit.md b/docs/intro/first-request/connecting-to-lit.md index 99de50ff..5f46f0fc 100644 --- a/docs/intro/first-request/connecting-to-lit.md +++ b/docs/intro/first-request/connecting-to-lit.md @@ -6,23 +6,23 @@ 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'; +import { LIT_NETWORK } from '@lit-protocol/constants'; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); ``` -### `LitNetwork` Constant +### `LIT_NETWORK` 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). +The `LIT_NETWORK` 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://v7-api-doc-lit-js-sdk.vercel.app/variables/constants_src.LIT_NETWORK.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`. +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://v7-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` @@ -38,13 +38,13 @@ In a browser environment, the `storageProvider` flag will be ignored, and the Se ```ts import { LitNodeClient } from '@lit-protocol/lit-node-client'; -import { LitNetwork } from '@lit-protocol/constants'; +import { LIT_NETWORK } from '@lit-protocol/constants'; import { disconnectWeb3 } from "@lit-protocol/auth-browser"; let litNodeClient; try { litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); @@ -90,7 +90,7 @@ The following is an example of a response to a request made using `LitNodeClient ### 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). +To learn more about `LitNodeClient` properties and methods, visit the [API Reference Docs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/core_src.LitCore.html). ### Code Example diff --git a/docs/intro/first-request/generating-session-sigs.md b/docs/intro/first-request/generating-session-sigs.md index 3fbaf1f7..9fd92b6d 100644 --- a/docs/intro/first-request/generating-session-sigs.md +++ b/docs/intro/first-request/generating-session-sigs.md @@ -34,7 +34,7 @@ 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. + - This function uses the [signSessionKey](https://v7-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. @@ -44,7 +44,7 @@ The best method to use depends on your use case. #### 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. +If you're using Node.js, the Session Signatures will be stored wherever the [storageProvider](https://v7-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 @@ -52,7 +52,7 @@ If you're executing within a browser environment, the Session Signatures will be ### 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). +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://v7-api-doc-lit-js-sdk.vercel.app/variables/constants_src.LIT_ABILITY.html). ### Table @@ -66,8 +66,6 @@ Session Signatures are used to grant access to specific resources on the Lit net | 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: diff --git a/docs/intro/first-request/making-first-decryption.md b/docs/intro/first-request/making-first-decryption.md index 6a0ee611..3e65602a 100644 --- a/docs/intro/first-request/making-first-decryption.md +++ b/docs/intro/first-request/making-first-decryption.md @@ -72,12 +72,13 @@ Additionally, we'll initialize an Ethereum wallet using the `ETHEREUM_PRIVATE_KE

```ts -import { LitNodeClient, encryptString, decryptToString } from "@lit-protocol/lit-node-client"; -import { LitNetwork, LIT_RPC } from "@lit-protocol/constants"; +import { LitNodeClient } from "@lit-protocol/lit-node-client"; +import { encryptString, decryptToString } from "lit-protocol/encryption"; +import { LIT_NETWORK, LIT_RPC } from "@lit-protocol/constants"; import * as ethers from "ethers"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false }); await litNodeClient.connect(); @@ -120,7 +121,7 @@ const accessControlConditions = [ ### Encrypting Data -The Lit SDK offers several methods for encrypting data, which you can explore [here](https://v6-api-doc-lit-js-sdk.vercel.app/modules/encryption_src.html). In this example, we'll use the [encryptString](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method. +The Lit SDK offers several methods for encrypting data, which you can explore [here](https://v7-api-doc-lit-js-sdk.vercel.app/modules/encryption_src.html). In this example, we'll use the [encryptString](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method. We start by defining the string we want to encrypt, stored in the `dataToEncrypt` variable. Using the `encryptString` method, we encrypt the data by providing the `accessControlConditions` (ACCs) and `dataToEncrypt` as parameters. This method returns an object containing: @@ -157,10 +158,10 @@ In this step, we'll generate Session Signatures that grant permission to decrypt

```ts +import { LIT_ABILITY } from "@lit-protocol/constants"; import { createSiweMessage, generateAuthSig, - LitAbility, LitAccessControlConditionResource, } from "@lit-protocol/auth-helpers"; @@ -175,7 +176,7 @@ const sessionSigs = await litNodeClient.getSessionSigs({ dataToEncryptHash ) ), - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback: async ({ @@ -206,7 +207,7 @@ const sessionSigs = await litNodeClient.getSessionSigs({ With the generated Session Signatures, we can proceed to decrypt the data using the `decryptToString` method. This method sends a decryption request to the Lit network, which verifies your permissions based on the ACCs and Session Signatures. -If all conditions are met, the data is decrypted and returned as a string. You can explore other decryption methods [here](https://v6-api-doc-lit-js-sdk.vercel.app/modules/encryption_src.html). +If all conditions are met, the data is decrypted and returned as a string. You can explore other decryption methods [here](https://v7-api-doc-lit-js-sdk.vercel.app/modules/encryption_src.html).

Click here to see how this is done diff --git a/docs/intro/first-request/making-first-signing.md b/docs/intro/first-request/making-first-signing.md index 67eaaddc..85d93c9f 100644 --- a/docs/intro/first-request/making-first-signing.md +++ b/docs/intro/first-request/making-first-signing.md @@ -78,11 +78,11 @@ Additionally, we'll initialize an Ethereum wallet using the `ETHEREUM_PRIVATE_KE ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork, LIT_RPC } from "@lit-protocol/constants"; +import { LIT_NETWORK, LIT_RPC } from "@lit-protocol/constants"; import * as ethers from "ethers"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false }); await litNodeClient.connect(); @@ -109,7 +109,7 @@ import { LitContracts } from "@lit-protocol/contracts-sdk"; const litContracts = new LitContracts({ signer: ethersWallet, - network: LitNetwork.DatilDev, + network: LIT_NETWORK.DatilDev, debug: false }); await litContracts.connect(); @@ -136,10 +136,10 @@ These permissions ensure that the session can only perform specific actions with

```ts +import { LIT_ABILITY } from "@lit-protocol/constants"; import { createSiweMessage, generateAuthSig, - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -150,11 +150,11 @@ const sessionSigs = await litNodeClient.getSessionSigs({ resourceAbilityRequests: [ { resource: new LitPKPResource(pkpInfo.tokenId), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], authNeededCallback: async ({ @@ -185,7 +185,7 @@ const sessionSigs = await litNodeClient.getSessionSigs({ With the generated Session Signatures, we can use the `pkpSign` method to sign our data using the PKP. In this example, we're signing the hash of the message **"The answer to the universe is 42."**. -If you'd like to see the `pkpSign` method's parameters, you can find them [here](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#pkpSign). +If you'd like to see the `pkpSign` method's parameters, you can find them [here](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#pkpSign).

Click here to see how this is done diff --git a/docs/network/migration-guide.md b/docs/network/migration-guide.md index 9d70da4b..8c4d4421 100644 --- a/docs/network/migration-guide.md +++ b/docs/network/migration-guide.md @@ -112,9 +112,9 @@ async decrypt(encryptedString, encryptedSymmetricKey) { ### 3. Connect to `Habanero` or `Manzano` and encrypt it again ```js import {ethers} from "ethers"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { LitAccessControlConditionResource, - LitAbility, createSiweMessageWithRecaps, generateAuthSig, } from "@lit-protocol/auth-helpers"; @@ -182,7 +182,7 @@ class LitV3 { // or Class LitV4 resourceAbilityRequests: [ { resource: litResource, - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback, diff --git a/docs/paying-for-lit/delegating-credit.md b/docs/paying-for-lit/delegating-credit.md index 8de4e59b..036f818f 100644 --- a/docs/paying-for-lit/delegating-credit.md +++ b/docs/paying-for-lit/delegating-credit.md @@ -85,16 +85,16 @@ The address corresponding to `process.env.ETHEREUM_PRIVATE_KEY` **needs** to be ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.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). +You can learn more about the `@lit-protocol/lit-node-client` package and what is offers using the [API reference docs](https://v7-api-doc-lit-js-sdk.vercel.app/modules/lit_node_client_src.html). ## Generating the Capacity Delegation Auth Sig @@ -113,7 +113,7 @@ const { capacityDelegationAuthSig } = #### `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. +This parameter is a [SignerLike](https://v7-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` diff --git a/docs/paying-for-lit/minting-capacity-credit/via-contract.md b/docs/paying-for-lit/minting-capacity-credit/via-contract.md index cb0ce847..48dd1456 100644 --- a/docs/paying-for-lit/minting-capacity-credit/via-contract.md +++ b/docs/paying-for-lit/minting-capacity-credit/via-contract.md @@ -66,16 +66,16 @@ const ethersSigner = new ethers.Wallet( ```ts import { LitContracts } from "@lit-protocol/contracts-sdk"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litContractClient = new LitContracts({ signer: ethersSigner, - network: LitNetwork.DatilTest, + network: LIT_NETWORK.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). +You can learn more about the `@lit-protocol/contracts-sdk` package and what is offers using the [API reference docs](https://v7-api-doc-lit-js-sdk.vercel.app/modules/contracts_sdk_src.html). ## Minting a Capacity Credit diff --git a/docs/paying-for-lit/using-delegated-auth-sig.md b/docs/paying-for-lit/using-delegated-auth-sig.md index 8bba3061..f2b90d43 100644 --- a/docs/paying-for-lit/using-delegated-auth-sig.md +++ b/docs/paying-for-lit/using-delegated-auth-sig.md @@ -72,7 +72,7 @@ ethers@v5 ```ts import ethers from "ethers"; -import { LIT_RPC } from "@lit-protocol/constants"; +import { LIT_RPC, LIT_ABILITY } from "@lit-protocol/constants"; const ethersSigner = new ethers.Wallet( process.env.ETHEREUM_PRIVATE_KEY, @@ -88,16 +88,16 @@ The address corresponding to `process.env.ETHEREUM_PRIVATE_KEY` **needs** to hav ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.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). +You can learn more about the `@lit-protocol/lit-node-client` package and what is offers using the [API reference docs](https://v7-api-doc-lit-js-sdk.vercel.app/modules/lit_node_client_src.html). ### Generating Session Sigs with the Delegation Auth Sig @@ -113,7 +113,7 @@ const sessionSigs = await litNodeClient.getSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], authNeededCallback: async ({ diff --git a/docs/sdk/access-control/encryption.md b/docs/sdk/access-control/encryption.md index cabceb83..5b5217ab 100644 --- a/docs/sdk/access-control/encryption.md +++ b/docs/sdk/access-control/encryption.md @@ -78,7 +78,7 @@ Within a file (in the Lit example repos it will likely be called `lit.js`), set ```jsx import * as LitJsSdk from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; class Lit { litNodeClient; @@ -90,7 +90,7 @@ class Lit { async connect() { this.litNodeClient = new LitJsSdk.LitNodeClient({ - litNetwork: "datil-dev", + litNetwork: LIT_NETWORK.DatilDev, }); await this.litNodeClient.connect(); } @@ -134,7 +134,7 @@ Running `litNodeClient.connect()` will return a promise that resolves when you ```jsx import * as LitJsSdk from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; class Lit { litNodeClient; @@ -147,7 +147,7 @@ class Lit { async connect() { app.locals.litNodeClient = new LitJsSdk.LitNodeClientNodeJs({ alertWhenUnauthorized: false, - litNetwork: "datil-dev", + litNetwork: LIT_NETWORK.DatilDev, debug: true, }); @@ -200,19 +200,15 @@ const accessControlConditions = [ To encrypt a string, use one of the following functions: -- [encryptString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) - Used to encrypt the raw string. -- - [encryptString()](../../) - Used to encrypt the raw string. -- [zipAndEncryptString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.zipAndEncryptString.html) - Compresses the string (using [JSZip](https://www.npmjs.com/package/jszip)) before encrypting it. This is useful for saving space, but takes additional time to perform the zip. +- [encryptString()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) - Used to encrypt the raw string. To encrypt a file, use: -- [encryptFile()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFile.html) - Used to encrypt a file without doing any zipping or packing. Because zipping larger files takes time, this function is useful when encrypting large files ( > 20mb). This also requires that you store the file metadata. -- [encryptFileAndZipWithMetadata()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFileAndZipWithMetadata.html) - Used to encrypt a file and then zip it up with the metadata (using [JSZip](https://www.npmjs.com/package/jszip)). This is useful for when you don't want to store the file metadata separately. -- [zipAndEncryptFiles()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.zipAndEncryptFiles.html) - Used to zip and encrypt multiple files. This does **not** include the file metadata in the zip, so you must store those yourself. +- [encryptFile()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFile.html) - Used to encrypt a file without doing any zipping or packing. Because zipping larger files takes time, this function is useful when encrypting large files ( > 20mb). This also requires that you store the file metadata. -Apart from these, we have one more function which can be used to encrypt both strings and files: +Apart from this, we have one more function which can be used to encrypt both strings and files: -- [encryptToJson()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptToJson.html) - Used to encrypt a string or file and serialize all the metadata required to decrypt i.e. accessControlConditions, evmContractConditions, solRpcConditions, unifiedAccessControlConditions & chain to JSON. It is useful for encrypting/decrypting data in IPFS or other storage without compressing it in a ZIP file. +- [encryptToJson()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptToJson.html) - Used to encrypt a string or file and serialize all the metadata required to decrypt i.e. accessControlConditions, evmContractConditions, solRpcConditions, unifiedAccessControlConditions & chain to JSON. It is useful for encrypting/decrypting data in IPFS or other storage without compressing it in a ZIP file. Encryption can be performed entirely client-side and doesn't require making a request to the Lit nodes. @@ -257,7 +253,7 @@ Both `ciphertext` and `dataToEncryptHash` will be base64 encoded strings. ### Performing Decryption -Make sure we have `accessControlConditions`, `ciphertext`, and the `dataToEncryptHash` data we created during the encryption step. An exception is when using `encryptFileAndZipWithMetadata()` which will include this metadata in the zip. +Make sure we have `accessControlConditions`, `ciphertext`, and the `dataToEncryptHash` data we created during the encryption step. There is just one step: @@ -282,13 +278,13 @@ npm i @lit-protocol/contracts-sdk The next step is to initialize a signer. This should be a wallet controlled by your application and the same wallet you’ll use to mint the Capacity Credit NFT: ```jsx -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const walletWithCapacityCredit = new Wallet(""); let contractClient = new LitContracts({ signer: dAppOwnerWallet, - network: LitNetwork.Datil, + network: LIT_NETWORK.Datil, }); await contractClient.connect(); @@ -356,10 +352,10 @@ If you want to obtain a `SessionSigs` in the browser, you can instantiate an `et ```jsx -import {ethers} from "ethers"; +import { ethers } from "ethers"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { LitAccessControlConditionResource, - LitAbility, createSiweMessageWithRecaps, generateAuthSig, } from "@lit-protocol/auth-helpers"; @@ -419,7 +415,7 @@ class Lit { resourceAbilityRequests: [ { resource: litResource, - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback, @@ -437,10 +433,10 @@ class Lit { If you want to obtain a `SessionSigs` on the server-side, you can instantiate an `ethers.wallet` to sign a SIWE message and then generate an `AuthSig` to get the `SessionSigs` as shown below: ```jsx -import {ethers} from "ethers"; +import { ethers } from "ethers"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { LitAccessControlConditionResource, - LitAbility, createSiweMessageWithRecaps, generateAuthSig, } from "@lit-protocol/auth-helpers"; @@ -501,7 +497,7 @@ class Lit { resourceAbilityRequests: [ { resource: litResource, - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback, @@ -525,11 +521,9 @@ If using a `mainnet` in order to keep the wallet which holds the `Capacity Credi To decrypt use the following functions depending on the function used to encrypt: -- [decryptToString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToString.html) for [encryptString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) -- [decryptToZip()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToZip.html) for [zipAndEncryptString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.zipAndEncryptString.html) & [zipAndEncryptFiles()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.zipAndEncryptFiles.html) -- [decryptToFile()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToFile.html) for [encryptFile()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFile.html) -- [decryptZipFileWithMetadata()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptZipFileWithMetadata.html) for [encryptFileAndZipWithMetadata()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFileAndZipWithMetadata.html) -- [decryptFromJson()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptFromJson.html) for [encryptToJson()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptToJson.html) +- [decryptToString()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToString.html) for [encryptString()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) +- [decryptToFile()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToFile.html) for [encryptFile()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFile.html) +- [decryptFromJson()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptFromJson.html) for [encryptToJson()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptToJson.html) In the example, we used `encryptString()` to encrypt so we will use `decryptToString()` to decrypt. Pass in the data `accessControlConditions`, `ciphertext`, `dataToEncryptHash`, and `authSig`. diff --git a/docs/sdk/access-control/quick-start.md b/docs/sdk/access-control/quick-start.md index 5ff357f7..65e21dc4 100644 --- a/docs/sdk/access-control/quick-start.md +++ b/docs/sdk/access-control/quick-start.md @@ -65,7 +65,7 @@ Within a file (in the Lit example repos it will likely be called `lit.js`), set ```jsx import * as LitJsSdk from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; class Lit { litNodeClient; @@ -77,7 +77,7 @@ class Lit { async connect() { this.litNodeClient = new LitJsSdk.LitNodeClient({ - litNetwork: "datil-dev", + litNetwork: LIT_NETWORK.DatilDev, }); await this.litNodeClient.connect(); } @@ -121,7 +121,7 @@ Running `litNodeClient.connect()` will return a promise that resolves when you ```jsx import * as LitJsSdk from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; class Lit { litNodeClient; @@ -134,7 +134,7 @@ class Lit { async connect() { app.locals.litNodeClient = new LitJsSdk.LitNodeClientNodeJs({ alertWhenUnauthorized: false, - litNetwork: "datil-dev", + litNetwork: LIT_NETWORK.DatilDev, debug: true, }); @@ -185,20 +185,17 @@ const accessControlConditions = [ ### Encryption -To encrypt a string, use one of the following functions: +To encrypt a string, use the following function: -- [encryptString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) - Used to encrypt the raw string. -- [zipAndEncryptString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.zipAndEncryptString.html) - Compresses the string (using [JSZip](https://www.npmjs.com/package/jszip)) before encrypting it. This is useful for saving space, but takes additional time to perform the zip. +- [encryptString()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) - Used to encrypt the raw string. To encrypt a file, use: -- [encryptFile()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFile.html) - Used to encrypt a file without doing any zipping or packing. Because zipping larger files takes time, this function is useful when encrypting large files ( > 20mb). This also requires that you store the file metadata. -- [encryptFileAndZipWithMetadata()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFileAndZipWithMetadata.html) - Used to encrypt a file and then zip it up with the metadata (using [JSZip](https://www.npmjs.com/package/jszip)). This is useful for when you don't want to store the file metadata separately. -- [zipAndEncryptFiles()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.zipAndEncryptFiles.html) - Used to zip and encrypt multiple files. This does **not** include the file metadatas in the zip, so you must store those yourself. +- [encryptFile()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFile.html) - Used to encrypt a file without doing any zipping or packing. Because zipping larger files takes time, this function is useful when encrypting large files ( > 20mb). This also requires that you store the file metadata. Apart from these, we have one more function which can be used to encrypt both strings and files: -- [encryptToJson()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptToJson.html) - Used to encrypt a string or file and serialise all the metadata required to decrypt i.e. accessControlConditions, evmContractConditions, solRpcConditions, unifiedAccessControlConditions & chain to JSON. It is useful for encrypting/decrypting data in IPFS or other storage without compressing it in a ZIP file. +- [encryptToJson()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptToJson.html) - Used to encrypt a string or file and serialise all the metadata required to decrypt i.e. accessControlConditions, evmContractConditions, solRpcConditions, unifiedAccessControlConditions & chain to JSON. It is useful for encrypting/decrypting data in IPFS or other storage without compressing it in a ZIP file. Encryption can be performed entirely client-side and doesn't require making a request to the Lit nodes. @@ -243,7 +240,7 @@ Both `ciphertext` and `dataToEncryptHash` will be base64 encoded strings. ## Performing Decryption -Make sure we have `accessControlConditions`, `ciphertext`, and the `dataToEncryptHash` data we created during the encryption step. An exception is when using `encryptFileAndZipWithMetadata()` which will include this metadata in the zip. +Make sure we have `accessControlConditions`, `ciphertext`, and the `dataToEncryptHash` data we created during the encryption step. There is just one step: @@ -268,13 +265,13 @@ npm i @lit-protocol/contracts-sdk The next step is to initialize a signer. This should be a wallet controlled by your application and the same wallet you’ll use to mint the Capacity Credit NFT: ```jsx -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const walletWithCapacityCredit = new Wallet(""); let contractClient = new LitContracts({ signer: dAppOwnerWallet, - network: LitNetwork.Datil, + network: LIT_NETWORK.Datil, }); await contractClient.connect(); @@ -344,10 +341,10 @@ If you want to obtain a `SessionSigs` in the browser, you can instantiate an `et ```jsx -import {ethers} from "ethers"; +import { ethers } from "ethers"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { LitAccessControlConditionResource, - LitAbility, createSiweMessageWithRecaps, generateAuthSig, } from "@lit-protocol/auth-helpers"; @@ -407,7 +404,7 @@ class Lit { resourceAbilityRequests: [ { resource: litResource, - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback, @@ -426,9 +423,9 @@ If you want to obtain a `SessionSigs` on the server-side, you can instantiate an ```jsx import {ethers} from "ethers"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { LitAccessControlConditionResource, - LitAbility, createSiweMessageWithRecaps, generateAuthSig, } from "@lit-protocol/auth-helpers"; @@ -486,7 +483,7 @@ class Lit { resourceAbilityRequests: [ { resource: litResource, - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback, @@ -510,11 +507,9 @@ If using a `mainnet` in order to keep the wallet which holds the `Capacity Credi To decrypt use the following functions depending on the function used to encrypt: -- [decryptToString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToString.html) for [encryptString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) -- [decryptToZip()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToZip.html) for [zipAndEncryptString()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.zipAndEncryptString.html) & [zipAndEncryptFiles()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.zipAndEncryptFiles.html) -- [decryptToFile()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToFile.html) for [encryptFile()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFile.html) -- [decryptZipFileWithMetadata()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptZipFileWithMetadata.html) for [encryptFileAndZipWithMetadata()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFileAndZipWithMetadata.html) -- [decryptFromJson()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptFromJson.html) for [encryptToJson()](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptToJson.html) +- [decryptToString()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToString.html) for [encryptString()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) +- [decryptToFile()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptToFile.html) for [encryptFile()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptFile.html) +- [decryptFromJson()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.decryptFromJson.html) for [encryptToJson()](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptToJson.html) In the example, we used `encryptString()` to encrypt so we will use `decryptToString()` to decrypt. Pass in the data `accessControlConditions`, `ciphertext`, `dataToEncryptHash`, and `authSig`. diff --git a/docs/sdk/authentication/session-sigs/capability-objects.md b/docs/sdk/authentication/session-sigs/capability-objects.md index c6f5eb4d..5e903822 100644 --- a/docs/sdk/authentication/session-sigs/capability-objects.md +++ b/docs/sdk/authentication/session-sigs/capability-objects.md @@ -13,6 +13,8 @@ When session capability objects are omitted from the `getSessionSigs()` function ## Grant Decryption Capability To Access Control Condition ```javascript +import { LIT_ABILITY } from "@lit-protocol/constants"; + // Create the session capability object const sessionCapabilityObject = new newSessionCapabilityObject(); @@ -23,7 +25,7 @@ const litResource = new LitAccessControlConditionResource('someResource'); // lit resource. sessionCapabilityObject.addCapabilityForResource( litResource, - LitAbility.AccessControlConditionDecryption + LIT_ABILITY.AccessControlConditionDecryption ); ``` @@ -55,7 +57,7 @@ const litResource = new LitAccessControlConditionResource('*'); // lit resource. sessionCapabilityObject.addCapabilityForResource( litResource, - LitAbility.AccessControlConditionDecryption + LIT_ABILITY.AccessControlConditionDecryption ); ``` diff --git a/docs/sdk/authentication/session-sigs/get-lit-action-session-sigs.md b/docs/sdk/authentication/session-sigs/get-lit-action-session-sigs.md index a40cfa04..1be4d965 100644 --- a/docs/sdk/authentication/session-sigs/get-lit-action-session-sigs.md +++ b/docs/sdk/authentication/session-sigs/get-lit-action-session-sigs.md @@ -22,7 +22,7 @@ Alternatively, the `getLitActionSessionSigs` function requires the form of authe Using this arragement, the function executes the Lit Action to determine authorization for the following step. -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`. +This function uses the [`signSessionKey`](https://v7-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. @@ -39,7 +39,7 @@ Before continuing this guide, you should have an understanding of: ## Parameters and Return Values -To see the parameters and return values of `getLitActionSessionSigs`, please visit our [API Docs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getLitActionSessionSigs). +To see the parameters and return values of `getLitActionSessionSigs`, please visit our [API Docs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getLitActionSessionSigs). ## Example Implementation @@ -99,12 +99,12 @@ const ethersSigner = new ethers.Wallet( Here we are initializing an instance of `LitNodeClient` and connecting it to the `datil-test` Lit network. ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; let litNodeClient: LitNodeClient; litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.DatilTest, debug: false, }); await litNodeClient.connect(); @@ -115,11 +115,11 @@ Here we are initializing an instance of `LitContracts`. This allows us to intera ```ts import { LitContracts } from "@lit-protocol/contracts-sdk"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litContracts = new LitContracts({ signer: ethersSigner, - network: LitNetwork.DatilTest, + network: LIT_NETWORK.DatilTest, debug: false, }); await litContracts.connect(); @@ -132,13 +132,13 @@ The current code uses the wildcard (`*`) identifier for `LitPKPResource`, which The wildcard identifier is also used for `LitActionResource`. This allows the session to execute **any** Lit Action. A more secure implementation would instead have a specific IPFS CID. -To get the Lit resource identifier for other resources, you can use the other methods included in [@lit-protocol/auth-helpers](https://v6-api-doc-lit-js-sdk.vercel.app/modules/auth_helpers_src.html) package. +To get the Lit resource identifier for other resources, you can use the other methods included in [@lit-protocol/auth-helpers](https://v7-api-doc-lit-js-sdk.vercel.app/modules/auth_helpers_src.html) package. If you would like to use this function on the `datil` or `datil-test` networks, a `capacityDelegationAuthSig` is required. Please also keep in mind that implementing this requires owning or minting a PKP and defining a Lit Action. How this is done can be found in the full code example. ```ts +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -150,11 +150,11 @@ const sessionSignatures = await litNodeClient.getLitActionSessionSigs({ resourceAbilityRequests: [ { resource: new LitPKPResource("*"), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], // With this setup you could use either the litActionIpfsId or the litActionCode property diff --git a/docs/sdk/authentication/session-sigs/get-pkp-session-sigs.md b/docs/sdk/authentication/session-sigs/get-pkp-session-sigs.md index f3d0c08c..ea72b4c1 100644 --- a/docs/sdk/authentication/session-sigs/get-pkp-session-sigs.md +++ b/docs/sdk/authentication/session-sigs/get-pkp-session-sigs.md @@ -18,7 +18,7 @@ Using the `getPkpSessionSigs` function, you can specify the capabilities of your This function requires you to own a PKP and some form of authentication to prove your identity (e.g. a custom Lit Action, AuthMethod, or AuthSig). It will enable specific abilities for your session keypair defined by the resources you specify. -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`. +This function uses the [`signSessionKey`](https://v7-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. @@ -31,7 +31,7 @@ Before continuing this guide, you should have an understanding of: ## Parameters and Returns Values -To see the parameters and return values of `getPkpSessionSigs`, please visit our [API Docs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs). +To see the parameters and return values of `getPkpSessionSigs`, please visit our [API Docs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs). ## Example Implementation @@ -91,12 +91,12 @@ const ethersSigner = new ethers.Wallet( Here we are initializing an instance of `LitNodeClient` and connecting it to the `datil-test` Lit network. ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; let litNodeClient: LitNodeClient; litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.DatilTest, debug: false, }); await litNodeClient.connect(); @@ -107,11 +107,11 @@ Here we are initializing an instance of `LitContracts`. This allows us to intera ```ts import { LitContracts } from "@lit-protocol/contracts-sdk"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litContracts = new LitContracts({ signer: ethersSigner, - network: LitNetwork.DatilTest, + network: LIT_NETWORK.DatilTest, debug: false, }); await litContracts.connect(); @@ -122,13 +122,14 @@ In this example, we're enabling our session to use a PKP for signing. The current code uses the wildcard (`*`) identifier for `LitPKPResource`, which grants signing abilities to **any** PKP. This should only be used for example implementations or debugging. A more secure implementation would instead use the PKP `tokenId` to grant signing abilities to a specific PKP. -To get the Lit resource identifier for other resources, you can use the other methods included in [@lit-protocol/auth-helpers](https://v6-api-doc-lit-js-sdk.vercel.app/modules/auth_helpers_src.html) package. +To get the Lit resource identifier for other resources, you can use the other methods included in [@lit-protocol/auth-helpers](https://v7-api-doc-lit-js-sdk.vercel.app/modules/auth_helpers_src.html) package. If you would like to use this function on the `datil` or `datil-test` networks, a `capacityDelegationAuthSig` is required. Please also keep in mind that implementing this requires owning or minting a PKP and some form of authentication (e.g. a custom Lit Action, Auth Method, or AuthSig). How this is done can be found in the full code example. ```ts -import { LitAbility, LitPKPResource } from "@lit-protocol/auth-helpers"; +import { LIT_ABILITY } from "@lit-protocol/constants"; +import { LitPKPResource } from "@lit-protocol/auth-helpers"; const sessionSignatures = await litNodeClient.getPkpSessionSigs({ pkpPublicKey: pkp.publicKey!, @@ -137,7 +138,7 @@ const sessionSignatures = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitPKPResource("*"), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes diff --git a/docs/sdk/authentication/session-sigs/get-session-sigs.md b/docs/sdk/authentication/session-sigs/get-session-sigs.md index 9e8fa49e..9e74f41c 100644 --- a/docs/sdk/authentication/session-sigs/get-session-sigs.md +++ b/docs/sdk/authentication/session-sigs/get-session-sigs.md @@ -28,7 +28,7 @@ Before continuing this guide, you should have an understanding of: ## Parameters and Returns Values -To see the parameters and return of `getSessionSigs`, please visit our [API Docs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getSessionSigs). +To see the parameters and return of `getSessionSigs`, please visit our [API Docs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getSessionSigs). ## Example Implementation @@ -85,27 +85,27 @@ Here we are initializing an instance of `LitNodeClient` and connecting it to the ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; let litNodeClient: LitNodeClient; litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.DatilTest, debug: false, }); await litNodeClient.connect(); ``` ### Generating Session Signatures -In this example, we're granting the capability to request to decrypt any data that we may be authorized to decrypt (i.e. we satisfy the Access Control Conditions the data was encrypted with). We could, however, specify the [LitAccessControlConditionResource](https://v6-api-doc-lit-js-sdk.vercel.app/classes/auth_helpers_src.LitAccessControlConditionResource.html) for specific encrypted data we're permitting the decryption capability for. In real-world applications, it's more common and secure to limit access to specific Lit resources instead of specifying the wildcard (`"*"`) identifier. +In this example, we're granting the capability to request to decrypt any data that we may be authorized to decrypt (i.e. we satisfy the Access Control Conditions the data was encrypted with). We could, however, specify the [LitAccessControlConditionResource](https://v7-api-doc-lit-js-sdk.vercel.app/classes/auth_helpers_src.LitAccessControlConditionResource.html) for specific encrypted data we're permitting the decryption capability for. In real-world applications, it's more common and secure to limit access to specific Lit resources instead of specifying the wildcard (`"*"`) identifier. -To get the Lit resource identifier for other resources, you can use the other methods included in [@lit-protocol/auth-helpers](https://v6-api-doc-lit-js-sdk.vercel.app/modules/auth_helpers_src.html) package. +To get the Lit resource identifier for other resources, you can use the other methods included in [@lit-protocol/auth-helpers](https://v7-api-doc-lit-js-sdk.vercel.app/modules/auth_helpers_src.html) package. If you would like to use this function on the `datil` or `datil-test` networks, a `capacityDelegationAuthSig` is required. An example of how to generate one can be found in the full code example. ```ts +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitAccessControlConditionResource, createSiweMessage, generateAuthSig, @@ -118,7 +118,7 @@ const sessionSignatures = await litNodeClient.getSessionSigs({ resourceAbilityRequests: [ { resource: new LitAccessControlConditionResource("*"), - ability: LitAbility.AccessControlConditionDecryption, + ability: LIT_ABILITY.AccessControlConditionDecryption, }, ], authNeededCallback: async ({ diff --git a/docs/sdk/authentication/session-sigs/intro.md b/docs/sdk/authentication/session-sigs/intro.md index 550e796a..55650582 100644 --- a/docs/sdk/authentication/session-sigs/intro.md +++ b/docs/sdk/authentication/session-sigs/intro.md @@ -12,7 +12,7 @@ Please do not cache Session Signatures, and instead generate them on-demand. Session Signatures are used to authenticate with the Lit nodes and create a secure connection to the Lit network. -Generating a Session Signature is required whenever you want to request a specific [Lit Ability](https://v6-api-doc-lit-js-sdk.vercel.app/enums/types_src.LitAbility.html) (e.g. signing a transaction) for a particular Lit Resource (e.g. a PKP). +Generating a Session Signature is required whenever you want to request a specific [Lit Ability](https://v7-api-doc-lit-js-sdk.vercel.app/variables/constants_src.LIT_ABILITY.html) (e.g. signing a transaction) for a particular Lit Resource (e.g. a PKP). Session Signatures are created using session keys, which are generated for you when you initiate a connection with the Lit network via the Lit SDK. These session keys are unique [`ed25519`](https://ed25519.cr.yp.to/) keypairs generated locally by the Lit SDK. They are used to sign all requests to the Lit network during the current session. @@ -43,9 +43,10 @@ A `storageProvider` needs to specified when creating an instance of the `LitNode ```javascript import { LocalStorage } from "node-localstorage"; +import { LIT_NETWORK } from "@lit-protocol/constants"; litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, // This storageProvider object can be omitted if executing in a browser storageProvider: { provider: new LocalStorage("./lit_storage.db"), diff --git a/docs/sdk/authentication/session-sigs/siws-pkp-session-sigs.md b/docs/sdk/authentication/session-sigs/siws-pkp-session-sigs.md index 1d573ab5..e0a17846 100644 --- a/docs/sdk/authentication/session-sigs/siws-pkp-session-sigs.md +++ b/docs/sdk/authentication/session-sigs/siws-pkp-session-sigs.md @@ -53,13 +53,13 @@ const authMethodId = ethers.utils.keccak256( ); ``` -Then we utilize the [mintNextAndAddAuthMethods](https://v6-api-doc-lit-js-sdk.vercel.app/classes/contracts_sdk_src.LitContracts.html#pkpHelperContractUtil) from the `@lit-protocol/contracts-sdk` package to mint the PKP and add the permitted auth methods to the PKP: +Then we utilize the [mintNextAndAddAuthMethods](https://v7-api-doc-lit-js-sdk.vercel.app/classes/contracts_sdk_src.LitContracts.html#pkpHelperContractUtil) from the `@lit-protocol/contracts-sdk` package to mint the PKP and add the permitted auth methods to the PKP: ```ts const tx = await litContractsClient.pkpHelperContract.write.mintNextAndAddAuthMethods( - AuthMethodType.LitAction, // keyType - [AuthMethodType.LitAction, authMethodType], // permittedAuthMethodTypes + AUTH_METHOD_TYPE.LitAction, // keyType + [AUTH_METHOD_TYPE.LitAction, authMethodType], // permittedAuthMethodTypes [ `0x${Buffer.from( ethers.utils.base58.decode( @@ -69,7 +69,7 @@ const tx = authMethodId, ], // permittedAuthMethodIds ["0x", "0x"], // permittedAuthMethodPubkeys - [[AuthMethodScope.SignAnything], [AuthMethodScope.NoPermissions]], // permittedAuthMethodScopes + [[AUTH_METHOD_SCOPE.SignAnything], [AUTH_METHOD_SCOPE.NoPermissions]], // permittedAuthMethodScopes true, // addPkpEthAddressAsPermittedAddress true, // sendPkpToItself { value: await litContractsClient.pkpNftContract.read.mintCost() } @@ -78,9 +78,9 @@ const receipt = await tx.wait(); ``` :::info -It's important to note that the first permitted Auth Method (the IPFS CID of the Lit Action) has the permission scope: `[AuthMethodScope.SignAnything]` which allows anything to be signed using the PKP, as long as the signing request is executed from within the Lit Action with the specific IPFS CID. +It's important to note that the first permitted Auth Method (the IPFS CID of the Lit Action) has the permission scope: `[AUTH_METHOD_SCOPE.SignAnything]` which allows anything to be signed using the PKP, as long as the signing request is executed from within the Lit Action with the specific IPFS CID. -The second permitted Auth Method (our custom Auth Method) has the permission scope: `[AuthMethodScope.NoPermissions]` which grants no signing permissions. This is desired because this Auth Method is only used by the Lit Action to check if a Solana public key is authorized to sign using the PKP. +The second permitted Auth Method (our custom Auth Method) has the permission scope: `[AUTH_METHOD_SCOPE.NoPermissions]` which grants no signing permissions. This is desired because this Auth Method is only used by the Lit Action to check if a Solana public key is authorized to sign using the PKP. ::: At this point, we have minted a PKP that is only authorized to sign within a specific Lit Action, and can check if a derived Solana public key from a signed SIWS message is authorized to sign using the PKP. diff --git a/docs/sdk/authentication/session-sigs/usage.md b/docs/sdk/authentication/session-sigs/usage.md deleted file mode 100644 index 4ba9954d..00000000 --- a/docs/sdk/authentication/session-sigs/usage.md +++ /dev/null @@ -1,88 +0,0 @@ ---- -sidebar_position: 3 ---- - -import FeedbackComponent from "@site/src/pages/feedback.md"; - -# Authenticate with SessionSigs - -Once you have obtained `SessionSigs`, you can use them to authenticate to the Lit nodes as shown in the examples below. - -## Making Signing Requests - -```javascript -var unifiedAccessControlConditions = [ - { - conditionType: "evmBasic", - contractAddress: "", - standardContractType: "", - chain: "ethereum", - method: "eth_getBalance", - parameters: [":userAddress", "latest"], - returnValueTest: { - comparator: ">=", - value: "10000000000000", - }, - }, -]; - -// Retrieving a signature -let jwt = await litNodeClient.getSignedToken({ - unifiedAccessControlConditions, - sessionSigs, -}); -``` - -## Making Encryption Requests - -```javascript -var unifiedAccessControlConditions = [ - { - conditionType: "evmBasic", - contractAddress: "", - standardContractType: "", - chain: "ethereum", - method: "eth_getBalance", - parameters: [":userAddress", "latest"], - returnValueTest: { - comparator: ">=", - value: "10000000000000", - }, - }, -]; -const chain = "ethereum"; - -// encrypt -const { ciphertext, dataToEncryptHash } = - await LitJsSdk.zipAndEncryptString( - { - unifiedAccessControlConditions, - chain, - sessionSigs, - dataToEncrypt: "this is a secret message", - }, - litNodeClient, - ); - -sessionSigs = await LitJsSdk.getSessionSigs({ - chain, - litNodeClient, - resourceAbilityRequests: [] -}); - -const decryptedFiles = await LitJsSdk.decryptToZip( - { - unifiedAccessControlConditions, - chain, - sessionSigs, - ciphertext, - dataToEncryptHash, - }, - litNodeClient, -); -const decryptedString = await decryptedFiles["string.txt"].async( - "text" -); -console.log("decrypted string", decryptedString); -``` - diff --git a/docs/sdk/capacity-credits.md b/docs/sdk/capacity-credits.md index ec909c12..43749b8a 100644 --- a/docs/sdk/capacity-credits.md +++ b/docs/sdk/capacity-credits.md @@ -25,12 +25,12 @@ A `Capacity Credits NFT` can be very easily minted from the Lit Explorer. So, he You’ll also need some `tstLPX` tokens for minting. These are test tokens that hold no real value and should only be used to pay for usage on Datil-test and Datil. `tstLPX` should only be claimed from the verified faucet, linked [here](https://chronicle-yellowstone-faucet.getlit.dev/). ```javascript -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const walletWithCapacityCredit = new Wallet(""); let contractClient = new LitContracts({ signer: dAppOwnerWallet, - network: LitNetwork.DatilTest, + network: LIT_NETWORK.DatilTest, }); await contractClient.connect(); @@ -67,10 +67,10 @@ Usage of your Capacity Credits NFT may be delegated to other wallets. To create Here we use the `capacityTokenId` we received when minting our Capacity Credit. ```javascript -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.DatilTest, checkNodeAttestation: true, }); @@ -110,12 +110,12 @@ Here we are delegating usage of `Capacity Credit` from a wallet which possesses ```javascript - import { LitNetwork } from "@lit-protocol/constants"; + import { LIT_NETWORK, LIT_ABILITY } from "@lit-protocol/constants"; const DELEGATEE_WALLET = new ethers.Wallet(your_private_key_string, provider); const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.DatilTest, checkNodeAttestation: true, }); await litNodeClient.connect(); @@ -131,12 +131,12 @@ Here we are delegating usage of `Capacity Credit` from a wallet which possesses recapObject.addCapabilityForResource( litResource, - LitAbility.LitActionExecution + LIT_ABILITY.LitActionExecution ); const verified = recapObject.verifyCapabilitiesForResource( litResource, - LitAbility.LitActionExecution + LIT_ABILITY.LitActionExecution ); if (!verified) { @@ -177,7 +177,7 @@ Here we are delegating usage of `Capacity Credit` from a wallet which possesses resourceAbilityRequests: [ { resource: new LitActionResource('*'), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], authNeededCallback, @@ -193,10 +193,10 @@ To Delegate to a pkp wallet from a wallet which possesses a `Capacity Credit` we For more information on session signatures and pkps see [here](./authentication/session-sigs/intro.md) ```javascript -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK, LIT_ABILITY } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilTest, + litNetwork: LIT_NETWORK.DatilTest, checkNodeAttestation: true, }); @@ -242,7 +242,7 @@ import { LitNetwork } from "@lit-protocol/constants"; resourceAbilityRequests: [ { resource: new LitPKPResource('*'), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ], authNeededCallback: pkpAuthNeededCallback, diff --git a/docs/sdk/installation.md b/docs/sdk/installation.md index 81a395f8..e9665b34 100644 --- a/docs/sdk/installation.md +++ b/docs/sdk/installation.md @@ -77,11 +77,11 @@ In this example stub, the litNodeClient is stored in a global variable `app.loca `app.locals.litNodeClient.connect()` returns a promise that resolves when you are connected to the Lit network. ```js -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; app.locals.litNodeClient = new LitJsSdk.LitNodeClientNodeJs({ alertWhenUnauthorized: false, - litNetwork: LitNetwork.Datil, + litNetwork: LIT_NETWORK.Datil, }); await app.locals.litNodeClient.connect(); ``` @@ -100,10 +100,10 @@ Within a file (in the Lit example repos it will likely be called `lit.js`), set `client.connect()` will return a promise that resolves when you are connected to the Lit Network. ```js -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const client = new LitJsSdk.LitNodeClient({ - litNetwork: LitNetwork.Datil, + litNetwork: LIT_NETWORK.Datil, }); await client.connect(); @@ -121,7 +121,7 @@ await client.disconnect(); ## Debug Logging and Lit Node Client configuration -The `LitNodeClient` object has a number of config params you can pass, documented here: [API Docs](https://v6-api-doc-lit-js-sdk.vercel.app/) +The `LitNodeClient` object has a number of config params you can pass, documented here: [API Docs](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.LitNodeClientConfig.html) For example, to turn off logging, you could set `debug` to `false` like this: `const client = new LitJsSdk.LitNodeClient({debug: false})` diff --git a/docs/sdk/migrations/7.0.0.md b/docs/sdk/migrations/7.0.0.md new file mode 100644 index 00000000..d68f5a3b --- /dev/null +++ b/docs/sdk/migrations/7.0.0.md @@ -0,0 +1,583 @@ +--- +sidebar_position: 4 +--- + +import FeedbackComponent from "@site/src/pages/feedback.md"; + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Migrating from 6.x.x to 7.x.x + +## Breaking Changes & Important Updates + +### Removal of Encryption Inclusion + +**Reference:** [Pull Request #608](https://github.com/LIT-Protocol/js-sdk/pull/608) + +#### **Changes:** + +- **Encryption Functions:** + - Added `encryptUint8Array` and `decryptToUint8Array` in `@lit-protocol/encryption` for handling `Uint8Array` data types. + - These functions unify encryption and decryption interfaces within the `@lit-protocol/encryption` package. +- **Function Relocations:** + - The following have been moved from `@lit-protocol/encryption` to `@lit-protocol/misc`: + - `isTokenOperator` + - `isValidBooleanExpression` + - `safeParams` + - `AccessControlConditionsValidatorProps` + - `AuthMaterialValidatorProps` + - `ParamsValidatorsType` +- **Export Changes:** + - Removed re-exports of `@lit-protocol/encryption` functions in `@lit-protocol/lit-node-client-nodejs`. + +#### **Migration Steps:** + +1. **Encrypting and Decrypting `Uint8Array`:** + - Replace usage of `encrypt` and `decrypt` functions in `LitNodeClient` with `encryptUint8Array` and `decryptToUint8Array` from `@lit-protocol/encryption`. + + ```jsx + import { encryptUint8Array, decryptToUint8Array } from '@lit-protocol/encryption'; + ``` + +2. **String and File Encryption/Decryption:** + - Functions like `encryptString`, `encryptFile`, `decryptString`, and `decryptFile` are no longer exported from `@lit-protocol/lit-node-client-nodejs` or `@lit-protocol/lit-node-client`. + - Import these exclusively from `@lit-protocol/encryption`. + + ```jsx + import { encryptString, decryptString } from '@lit-protocol/encryption'; + ``` + +3. **Moved Functions and Interfaces:** + - Import the following from `@lit-protocol/misc`: + + ```jsx + import { + isTokenOperator, + isValidBooleanExpression, + safeParams, + AccessControlConditionsValidatorProps, + AuthMaterialValidatorProps, + ParamsValidatorsType, + } from '@lit-protocol/misc'; + ``` + + +--- + +### Changes to Enums and Constants + +**Reference:** Pull Request [#579](https://github.com/LIT-Protocol/js-sdk/pull/579) + +#### **Changes:** + +- **Enums Replaced with Constants:** + - All enums are now constants in `@lit-protocol/constants`. + - Types representing keys and values are exported with `_TYPE` and `_VALUE` suffixes. +- **Adjusted Network Configurations:** + - Constants no longer include `localhost` or `internalDev`. + - Use the `.Custom` property for custom networks. + +#### **Migration Steps:** + +1. **Update Enums to Constants:** + - Replace old enums with new constants. + - Use corresponding types for type safety. +2. **Specific Enum to Constant Replacements:** + + + | Old Enum/Constant | New Constant | + | --- | --- | + | `WALLET_ERROR` | `WALLET_ERROR` (as a constant) | + | `LitAbility` | `LIT_ABILITY` | + | `LitNamespace` | `LIT_NAMESPACE` | + | `LitRecapAbility` | `LIT_RECAP_ABILITY` | + | `LitResourcePrefix` | `LIT_RESOURCE_PREFIX` | + | `AuthMethodScope` | `AUTH_METHOD_SCOPE` | + | `AuthMethodType` | `AUTH_METHOD_TYPE` | + | `CENTRALISATION_BY_NETWORK` | Use `CENTRALISATION_BY_NETWORK.Custom` | + | `EITHER_TYPE` | `EITHER_TYPE` | + | `GENERAL_WORKER_URL_BY_NETWORK` | Use `GENERAL_WORKER_URL_BY_NETWORK.Custom` | + | `HTTP_BY_NETWORK` | Use `HTTP_BY_NETWORK.Custom` | + | `LIT_CURVE` | `LIT_CURVE` | + | `LIT_ENDPOINT_VERSION` | `LIT_ENDPOINT_VERSION` | + | `LIT_NETWORKS` | Use `LIT_NETWORKS.Custom` | + | `LitErrorKind` | `LIT_ERROR_KIND` | + | `LitNetwork` | `LIT_NETWORK` | + | `METAMASK_CHAIN_INFO_BY_NETWORK` | Use `METAMASK_CHAIN_INFO_BY_NETWORK.Custom` | + | `ProviderType` | `PROVIDER_TYPE` | + | `RELAYER_URL_BY_NETWORK` | Use `RELAYER_URL_BY_NETWORK.Custom` | + | `RPC_URL_BY_NETWORK` | Use `RPC_URL_BY_NETWORK.Custom` | + | `StakingStates` | `STAKING_STATES` | + | `VMTYPE` | `VMTYPE` | + | `metamaskChainInfo` | `METAMASK_CHAIN_INFO` | + | `LogLevel` | `LOG_LEVEL` | + | `IRelayAuthStatus` | `RELAY_AUTH_STATUS` | + +3. **Example of Updating Imports:** + + ```jsx + // Old import + import { LitNetwork } from '@lit-protocol/constants'; + + // New import + import { LIT_NETWORK, LIT_NETWORK_TYPE, LIT_NETWORK_VALUE } from '@lit-protocol/constants'; + ``` + +4. **Handling Custom Networks:** + - For configurations no longer including `localhost`, use the `.Custom` property. + + ```jsx + const network = LIT_NETWORKS.Custom; + const rpcUrl = RPC_URL_BY_NETWORK.Custom; + ``` + +5. **Backwards Compatibility:** + - Old names are temporarily available but will be removed in the future. + - Update your code to use the new constants. + +--- + +### Replacement of `throwError` Function + +**Reference:** Pull Request [#576migr](https://github.com/LIT-Protocol/js-sdk/pull/576) + +#### **Changes:** + +- **Error Handling:** + - The `throwError` function has been removed from the SDK. + - Custom error classes based on `VError` are now used throughout the SDK for error handling. +- **TypeScript and ESLint Improvements:** + - Types across the SDK have been improved to enhance TypeScript and ESLint validations. + +#### **Migration Steps:** + +1. **Error Handling with `VError`:** + - Update your error handling logic to work with `VError` instances. + - Errors thrown by the SDK can now be treated as `VError`s, allowing for extended error information. + - Errors thrown from the SDK will all be `instanceof Error` (VError extends Error), and will include a `.stack` property +2. **Update Error Catch Blocks:** + + ```jsx + import { VError } from '@openagenda/verror'; + + try { + // SDK operations + } catch (error) { + if (error instanceof VError) { + // Extract extended error information + const info = VError.info(error); + console.error('Error message:', error.message); + console.error('Error info:', info); + } else { + // Handle other errors + console.error('An unexpected error occurred:', error); + } + } + + ``` + +3. **Refer to Documentation:** + - Check the project `README.md` or [official documentation](https://www.npmjs.com/package/verror) for detailed instructions on handling `VError` instances to obtain extended error information. + +--- + +### Removal of `LitAuthClient` + +**Reference:** Pull Request [#547](https://github.com/LIT-Protocol/js-sdk/pull/547) + +#### **Changes:** + +- **Removal of `LitAuthClient`:** + - The `LitAuthClient` class has been removed from the SDK. + - Users should now initialize providers directly. +- **Function Relocations:** + - Static method `LitAuthClient.getAuthIdByAuthMethod` is now a standalone function in `@lit-protocol/lit-auth-client`. + - Method `mintPKPWithAuthMethods` in `LitAuthClient` is now a method in `LitRelay`. +- **Export Changes:** + - `LitRelay` is now exported from `@lit-protocol/lit-auth-client`. + - Added `LitRelay.getRelayUrl(litNetwork: LitNetwork)` static method. +- **Deprecations and Additions:** + - Marked `BaseProvider.fetchPKPsThroughRelayer` as deprecated. + - Added `BaseProvider.getPKPsForAuthMethod` and `BaseProvider.fetchPKPs` instance methods. + +#### **Migration Steps:** + +1. **Initializing Providers Directly:** + - **Old Way with `LitAuthClient`:** + + ```jsx + const someProvider = litAuthClient.initProvider(ProviderType.ProviderType); + ``` + + - **New Way Without `LitAuthClient`:** + + ```jsx + import { LitRelay, EthWalletProvider } from '@lit-protocol/lit-auth-client'; + import { LitNodeClient } from '@lit-protocol/lit-node-client'; + + const litNodeClient = new LitNodeClient(); + await litNodeClient.connect(); + const relay = new LitRelay({ litNetwork: LIT_NETWORK.MAINNET }); + + const ethWalletProvider = new EthWalletProvider({ relay, litNodeClient }); + ``` + +2. **Replacing `LitAuthClient.getAuthIdByAuthMethod`:** + + ```jsx + import { getAuthIdByAuthMethod } from '@lit-protocol/lit-auth-client'; + + const authId = getAuthIdByAuthMethod(authMethod); + ``` + +3. **Minting PKPs with `LitRelay`:** + + ```jsx + import { LitRelay } from '@lit-protocol/lit-auth-client'; + + const relay = new LitRelay({ litNetwork: LIT_NETWORK.MAINNET }); + + relay.mintPKPWithAuthMethods(authMethods, options); + ``` + +4. **Updating Provider Methods:** + - **Deprecated Method:** + + ```jsx + provider.fetchPKPsThroughRelayer(...); + ``` + + - **Replacement Methods:** + + ```jsx + // Fetch PKPs directly from the blockchain + const pkps = await provider.fetchPKPs(...); + + // Or get PKPs for a specific auth method + const pkps = await provider.getPKPsForAuthMethod(authMethod); + ``` + +5. **Using `LitRelay.getRelayUrl`:** + + ```jsx + import { LitRelay } from '@lit-protocol/lit-auth-client'; + import { LIT_NETWORK } from '@lit-protocol/constants'; + + const relayUrl = LitRelay.getRelayUrl(LIT_NETWORK.MAINNET); + ``` + + +--- + +### Removal of `PKPClient` + +**Reference:** Pull Request [#541](https://github.com/LIT-Protocol/js-sdk/pull/541) + +#### **Changes:** + +- **Removal of `PKPClient`:** + - `PKPClient` has been removed from the SDK. + - Previously, `PKPClient` was used to abstract different wallet types. +- **Updates to `PKPWalletConnect`:** + - Now uses `PKPEthersWallet` instead of `PKPClient`, as only Ethereum wallets are supported. + - Methods in `PKPWalletConnect` have been updated to reflect this change. + - Improved type definitions in `PKPWalletConnect`. + +#### **Migration Steps:** + +1. **Replace Usage of `PKPClient`:** + + ```jsx + // Old + const pkpClient = new PKPClient(...); + + // New + const pkpEthersWallet = new PKPEthersWallet(...); + ``` + +2. **Update Methods in `PKPWalletConnect`:** + + + | Old Method | New Method | + | --- | --- | + | `addPKPClient` | `addPKPEthersWallet` | + | `findPKPClientByRequestParams` | `findPKPEthersWalletByRequestParams` | + | `getPKPClients` | `getPKPEthersWallets` | + | `setPKPClients` | `setPKPEthersWallets` | + - All methods now work with `PKPEthersWallet` instances instead of `PKPClient`. +3. **Adjust Types and Interfaces:** + - Update any types or interfaces that used `PKPClient` to use `PKPEthersWallet` or `PKPCosmosWallet`. +4. **Example of Updating Code:** + + ```jsx + // Old way + const pkpWalletConnect = new PKPWalletConnect(); + pkpWalletConnect.addPKPClient(pkpClient); + + // New way + const pkpWalletConnect = new PKPWalletConnect(); + pkpWalletConnect.addPKPEthersWallet(pkpEthersWallet); + ``` + +5. **Note on Supported Wallets:** + - Since only Ethereum wallets (`PKPEthersWallet`) are currently supported, ensure that your implementation aligns with this. + +--- + +### Updates to PKP Wallet Classes + +**Reference:** Pull Request [#509](https://github.com/LIT-Protocol/js-sdk/pull/509) + +#### **Changes:** + +- **Class Structure Adjustments:** + - `PKPBase` class has been made final (private constructor) to prevent extension. + - `PKPEthersWallet`, `PKPCosmosWallet`, and `PKPSuiWallet` no longer extend `PKPBase` but implement a shared interface. + - Public interfaces of these classes have been restricted for better encapsulation. +- **Initialization Changes:** + - `litNodeClient` is now a required parameter when initializing PKP wallets. + - Fields to create `litNodeClient` within PKP wallets have been removed; responsibility is delegated to the user. +- **Removal of Redundant Instances:** + - Removed redundant `litNodeClient` instance inside `authContext`. +- **Updates to `PKPClient`:** + - Updated `PKPClient` due to changes in PKP wallet classes. +- **Type Definitions:** + - Fixed several type definitions for improved type safety. +- **Demo App Updates:** + - Updated session signatures demo app to use all PKP wallet classes for testing signing. + +#### **Migration Steps:** + +1. **Initialize PKP Wallets with `litNodeClient`:** + - **Old Way:** + + ```jsx + const pkpEthersWallet = new PKPEthersWallet({ pkpPublicKey, controllerAuthSig }); + ``` + + - **New Way:** + + ```jsx + import { LitNodeClient } from '@lit-protocol/lit-node-client'; + + const litNodeClient = new LitNodeClient(); + await litNodeClient.connect(); + + const pkpEthersWallet = new PKPEthersWallet({ + pkpPublicKey, + controllerAuthSig, + litNodeClient, + }); + ``` + +2. **Adjust Class Extensions and Interfaces:** + - If you extended `PKPBase`, refactor your code as extending `PKPBase` is no longer supported. + - Implement the shared interface if custom PKP wallet functionality is needed. +3. **Removal of `WalletFactory`:** + - Since `WalletFactory` has been removed, instantiate PKP wallets directly. + + ```jsx + // Old way + const pkpWallet = WalletFactory.createWallet(...); + + // New way + const pkpWallet = new PKPEthersWallet({ ... }); + ``` + +4. **Update `PKPClient` Usage:** + - If you use `PKPClient`, update it to align with the new PKP wallet classes. +5. **Review Type Definitions:** + - Update any type definitions that may have changed due to stricter typing. +6. **Demo App Testing:** + - If you have custom demo apps or tests, update them to use the new PKP wallet classes accordingly. + +--- + +### Migration of WASM Packages and Updates to Crypto Module + +**Reference:** Pull Request [#503](https://github.com/LIT-Protocol/js-sdk/pull/503) + +#### **Changes:** + +- **Consolidation of WASM Packages:** + - Migrated the following repositories into a single `packages/wasm` directory within the SDK: + - `lit-bls-wasm` + - `lit-ecdsa-wasm-combine` + - `sev-snp-utils-wasm` +- **Build Process Updates:** + - The `packages/wasm` is now built with each run of the build pipelines. + - Emits type declarations and new compiled binaries embedded into the binding wrapper. + - Reduced the size of binding + WASM to approximately 393 KB. +- **Cryptographic Implementations Upgrade:** + - Upgraded cryptographic implementations. + - Now using the `hd-keys-curves` library over hand-migrated implementations for HD key derivation. +- **Async Implementations in Crypto Module:** + - Migrated `packages/crypto` to async implementations. + - Scoped invocation of `loadModule` to lazy-load the WASM module. +- **CI/CD Pipeline Updates:** + - Updated GitHub Action jobs to use Rust toolchains for building `packages/wasm`. + +#### **Migration Steps:** + +1. **Update Imports for WASM Modules:** + - Update your imports to point to the new `@lit-protocol/wasm` package. + + ```jsx + // Old import + import { someFunction } from 'lit-bls-wasm'; + + // New import + import { someFunction } from '@lit-protocol/wasm'; + ``` + +2. **Handle Async Implementations in Crypto Module:** + - Ensure that you await functions in the crypto module as they are now async. + + ```jsx + // Old synchronous usage + const result = cryptoFunction(data); + + // New async usage + const result = await cryptoFunction(data); + ``` + +3. **Initialization of WASM Modules:** + - WASM modules now lazy-load when their functions are called. No manual initialization is required. +4. **Update HD Key Derivation Usage:** + - Review any key derivation logic to ensure compatibility with the `hd-keys-curves` library. +5. **Review Bundle Sizes:** + - With the consolidation, your application's bundle size may be reduced. +6. **Testing:** + - Thoroughly test cryptographic functionalities in your application. + +--- + +### Renaming of `getRequestId` Method + +**Reference:** Latest Pull Request + +#### **Changes:** + +- **Method Renaming:** + - The method `getRequestId` has been renamed to `_getNewRequestId` to avoid confusion with `getRequestIds`. + - The method `_getNewRequestId` is now a protected method. + +#### **Migration Steps:** + +1. **Update Method Calls:** + - If you were using `getRequestId`, you need to update your code as follows: + - **Old Method:** + + ```jsx + const requestId = this.getRequestId(); + ``` + + - **New Method:** + - Since `_getNewRequestId` is now a protected method, it cannot be called from outside the class or subclass. + - If you need a new request ID within a subclass, you can call: + + ```jsx + const requestId = this._getNewRequestId(); + ``` + + - If you're outside the class and previously relied on `getRequestId`, you will need to refactor your code since the method is no longer publicly accessible. +2. **Avoid Misuse of Request IDs:** + - The change aims to prevent consumers from generating request IDs that are not used. + - Review your code to ensure that request IDs are managed appropriately within the SDK's classes. +3. **Refactor Code if Necessary:** + - If your code relied on obtaining a new request ID from `getRequestId`, consider whether this is necessary. + - The SDK likely manages request IDs internally, and external generation is probably not needed. + +--- + +### Removal of Compression Functions + +**Reference:** Pull Request #621 + +#### **Changes:** + +- **Removed Functions from `@lit-protocol/encryption`:** + - The following functions have been removed: + - `encryptZip` + - `zipAndEncryptString` + - `zipAndEncryptFiles` + - `encryptFileAndZipWithMetadata` + - `decryptToZip` + - `decryptZipFileWithMetadata` +- **Dependency Removal:** + - Removed `jszip` from the bundle to reduce the bundle size. + +#### **Migration Steps:** + +1. **Handle Compression Yourself:** + - If you are using any of the removed functions, you now need to handle compression separately. + - **Removed Functions:** + - `encryptZip` + - `zipAndEncryptString` + - `zipAndEncryptFiles` + - `encryptFileAndZipWithMetadata` + - `decryptToZip` + - `decryptZipFileWithMetadata` +2. **Steps to Replace Removed Functions:** + - **Compression:** + - Use a compression library like `jszip` or `pako` directly in your application. + - Compress your data before encryption or decompress after decryption. + + ```jsx + import { zip, unzip } from 'your-preferred-compression-library'; + import { encryptUint8Array, decryptToUint8Array } from '@lit-protocol/encryption'; + + // Compress data + const compressedData = zip(data); + + // Encrypt compressed data + const encryptedData = await encryptUint8Array({ + uint8Array: compressedData, + // ...other parameters + }); + + // Decrypt data + const decryptedData = await decryptToUint8Array({ + // ...parameters + }); + + // Decompress data + const originalData = unzip(decryptedData); + ``` + + - **Encryption:** + - Use the encryption functions provided in `@lit-protocol/encryption` after you handle compression. +3. **Update Your Dependencies:** + - Add your chosen compression library to your project's dependencies. +4. **Review Bundle Size:** + - By managing compression separately, you can optimize your bundle size based on your application's needs. +5. **Testing:** + - Test your compression and encryption/decryption flows thoroughly to ensure data integrity. + +--- + +## General Recommendations + +- **Review and Update All Imports:** + - Ensure all your imports reference the correct packages and updated constants or functions. +- **Type Safety:** + - Utilize the provided `_TYPE` and `_VALUE` types for enhanced type checking. +- **Avoid Deprecated References:** + - Do not use old enums, classes, methods, or duplicated exports to benefit from reduced bundle sizes and future compatibility. +- **Error Handling:** + - Update your error handling to accommodate the new custom error classes based on `VError`. +- **Async Adjustments:** + - Update your code to handle async functions, especially in the crypto module. +- **Compression Handling:** + - Manage compression independently using a library that suits your needs. +- **Testing:** + - Thoroughly test your application after making these changes to ensure everything functions as expected. + +--- + +## Summary + +By following this migration guide, you will align your codebase with the latest updates to the Lit Protocol SDK, ensuring better modularity, type safety, enhanced error handling, and reduced bundle sizes. The updates simplify provider and wallet initialization, improve cryptographic implementations, enforce better encapsulation and method usage, and give you control over compression handling. + +**Note:** While backward compatibility is temporarily maintained for some constants and functions, it is advisable to update your code promptly to use the new constants, functions, and error handling mechanisms to prevent future breaking changes. \ No newline at end of file diff --git a/docs/sdk/serverless-signing/deploying.md b/docs/sdk/serverless-signing/deploying.md index 579b8e55..d1debaa1 100644 --- a/docs/sdk/serverless-signing/deploying.md +++ b/docs/sdk/serverless-signing/deploying.md @@ -47,7 +47,7 @@ However, it's important to note some potential drawbacks: ## Deploying Using a Code String -This method is the more straightforward of the two, as we're simply providing our Lit Action code as a string when using one of the Lit SDK methods such as [executeJs](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.ILitNodeClient.html#executeJs). +This method is the more straightforward of the two, as we're simply providing our Lit Action code as a string when using one of the Lit SDK methods such as [executeJs](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.ILitNodeClient.html#executeJs). :::note Most of the code in the full implementation is boilerplate code used to connect to a Lit network and generate Session Signatures. If you don't understand all of the code, or want to learn more about it, you can go [here](../../connecting-to-a-lit-network/connecting.md) to learn about connecting to a network, and [here](../authentication/session-sigs/intro.md) to learn more about generating Session Signatures. @@ -59,11 +59,10 @@ Most of the code in the full implementation is boilerplate code used to connect ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LIT_RPC, LitNetwork } from "@lit-protocol/constants"; +import { LIT_RPC, LIT_NETWORK, LIT_ABILITY } from "@lit-protocol/constants"; import { createSiweMessageWithRecaps, generateAuthSig, - LitAbility, LitActionResource, } from "@lit-protocol/auth-helpers"; @@ -73,7 +72,7 @@ const ethersSigner = new ethers.Wallet( ); const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -84,7 +83,7 @@ const sessionSigs = await litNodeClient.getSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], authNeededCallback: async ({ @@ -144,7 +143,7 @@ Next we're calling the `executeJs` method to create a request to the Lit network ## Deploying Using IPFS -While providing a code string is generally recommended, there are scenarios where uploading your Lit Action to IPFS can be beneficial as covered above. To implement this, we pass the [IPFS Content Identifier (CID)](https://docs.ipfs.tech/quickstart/publish/#cids-explained) when calling Lit SDK methods such as [executeJs](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.ILitNodeClient.html#executeJs). +While providing a code string is generally recommended, there are scenarios where uploading your Lit Action to IPFS can be beneficial as covered above. To implement this, we pass the [IPFS Content Identifier (CID)](https://docs.ipfs.tech/quickstart/publish/#cids-explained) when calling Lit SDK methods such as [executeJs](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.ILitNodeClient.html#executeJs). :::note Most of the code in the full implementation is boilerplate code used to connect to a Lit network and generate Session Signatures. If you don't understand all of the code, or want to learn more about it, you can go [here](../../connecting-to-a-lit-network/connecting.md) to learn about connecting to a network, and [here](../authentication/session-sigs/intro.md) to learn more about generating Session Signatures. @@ -156,11 +155,10 @@ Most of the code in the full implementation is boilerplate code used to connect ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LIT_RPC, LitNetwork } from "@lit-protocol/constants"; +import { LIT_RPC, LIT_NETWORK, LIT_ABILITY } from "@lit-protocol/constants"; import { createSiweMessageWithRecaps, generateAuthSig, - LitAbility, LitActionResource, } from "@lit-protocol/auth-helpers"; @@ -170,7 +168,7 @@ const ethersSigner = new ethers.Wallet( ); const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -181,7 +179,7 @@ const sessionSigs = await litNodeClient.getSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], authNeededCallback: async ({ diff --git a/docs/sdk/serverless-signing/key-claiming.md b/docs/sdk/serverless-signing/key-claiming.md index d9723d2c..3db0c727 100644 --- a/docs/sdk/serverless-signing/key-claiming.md +++ b/docs/sdk/serverless-signing/key-claiming.md @@ -47,12 +47,14 @@ const keyId = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("theIPFSIdOfYourLi ### Adding an auth method when minting a claim ```jsx +import { getAuthIdByAuthMethod } from '@lit-protocol/lit-auth-client'; + const authMethod = { - authMethodType: AuthMethodType.EthWallet, + authMethodType: AUTH_METHOD_TYPE.EthWallet, accessToken: JSON.stringify(authSig), }; - const authMethodId = LitAuthClient.getAuthMethodId(authMethod); + const authMethodId = getAuthIdByAuthMethod(authMethod); const keyId = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("theIPFSIdOfYourLitAction_yourUserId")) @@ -75,7 +77,7 @@ const keyId = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("theIPFSIdOfYourLi permittedIpfsCIDScopes: [], permittedAddresses: [], permittedAddressScopes: [], - permittedAuthMethodTypes: [AuthMethodType.EthWallet], + permittedAuthMethodTypes: [AUTH_METHOD_TYPE.EthWallet], permittedAuthMethodIds: [`0x${authMethodId}`], permittedAuthMethodPubkeys: [`0x`], permittedAuthMethodScopes: [[BigNumber.from("1")]], diff --git a/docs/sdk/serverless-signing/quick-start.md b/docs/sdk/serverless-signing/quick-start.md index 7d47a6bf..e945cb10 100644 --- a/docs/sdk/serverless-signing/quick-start.md +++ b/docs/sdk/serverless-signing/quick-start.md @@ -60,7 +60,7 @@ You should use **at least Node v19.9.0** for ### Connecting to the Lit Network -Running a Lit Action requires an active connection to the Lit network. This can be done by initializing a [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) instance, which will establish a connection to the Lit nodes. +Running a Lit Action requires an active connection to the Lit network. This can be done by initializing a [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) instance, which will establish a connection to the Lit nodes. We will also be initializing an Ethereum wallet using the `ETHEREUM_PRIVATE_KEY` environment variable, which is required for generating session signatures in this example. @@ -70,11 +70,11 @@ We will also be initializing an Ethereum wallet using the `ETHEREUM_PRIVATE_KEY` ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork, LIT_RPC } from "@lit-protocol/constants"; +import { LIT_NETWORK, LIT_RPC } from "@lit-protocol/constants"; import * as ethers from "ethers"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false }); await litNodeClient.connect(); @@ -97,8 +97,8 @@ Session signatures are used to authenticate and maintain an active connection to

```ts +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, createSiweMessage, generateAuthSig, @@ -110,7 +110,7 @@ const sessionSignatures = await litNodeClient.getSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], authNeededCallback: async ({ @@ -167,7 +167,7 @@ To execute the Lit Action, we use the `executeJs` function. You'll need to pass If you'd like to use the IPFS method mentioned previously, you would instead use `ipfsId` instead of `code: litActionCode`, and the `ipfsId` would be the IPFS CID of the Lit Action code. -More details on the `executeJs` method can be found [here](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.JsonExecutionSdkParams.html). +More details on the `executeJs` method can be found [here](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.JsonExecutionSdkParams.html).

Click here to see how this is done diff --git a/docs/user-wallets/pkps/advanced-topics/auth-methods/add-remove-auth-methods.md b/docs/user-wallets/pkps/advanced-topics/auth-methods/add-remove-auth-methods.md index 5fda5c89..e51d6e83 100644 --- a/docs/user-wallets/pkps/advanced-topics/auth-methods/add-remove-auth-methods.md +++ b/docs/user-wallets/pkps/advanced-topics/auth-methods/add-remove-auth-methods.md @@ -16,13 +16,13 @@ You can only pass one of the three. If you pass more than one, `PKPEthersWallet` ```js import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitAbility, LitActionResource } from '@lit-protocol/auth-helpers'; +import { LitActionResource } from '@lit-protocol/auth-helpers'; import { PKPEthersWallet } from "@lit-protocol/pkp-ethers"; -import { LIT_RPC, LitNetwork } from "@lit-protocol/constants"; +import { LIT_RPC, LIT_NETWORK, LIT_ABILITY } from "@lit-protocol/constants"; // If you haven't done before, create a LitNodeClient instance const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, }); await litNodeClient.connect(); @@ -30,7 +30,7 @@ await litNodeClient.connect(); const resourceAbilities = [ { resource: new LitActionResource("*"), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ]; @@ -46,8 +46,8 @@ const authNeededCallback = async (params: AuthCallbackParams) => { }; const pkpWallet = new PKPEthersWallet({ + litNodeClient, authContext: { - client: litNodeClient, getSessionSigsProps: { chain: 'ethereum', expiration: new Date(Date.now() + 60_000 * 60).toISOString(), diff --git a/docs/user-wallets/pkps/advanced-topics/auth-methods/custom-auth.md b/docs/user-wallets/pkps/advanced-topics/auth-methods/custom-auth.md index ba2d946d..ea544429 100644 --- a/docs/user-wallets/pkps/advanced-topics/auth-methods/custom-auth.md +++ b/docs/user-wallets/pkps/advanced-topics/auth-methods/custom-auth.md @@ -28,7 +28,7 @@ Inside of your Lit Actions, there is an object called `Lit.Auth` that will be pr - actionIpfsIds: An array of IPFS IDs that are being called by this Lit Action. This will typically only have a single item, but if you call multiple Lit Actions from inside your Lit Action, they will all be included here. For example, if you have two Lit Actions, A, and B, and A calls B, then the first item in the array will be A and the last item will be B. Therefore, the last item in the array is always the IPFS ID of the Lit Action that is currently running. - authSigAddress: A verified wallet address, if one was passed in. This is the address that was used to sign the AuthSig. -- authMethodContexts: An array of auth method contexts. Each entry will contain the following items: `userId`, `appId`, and `authMethodType`. A list of AuthMethodTypes can be found [here](./overview.md) in the docs. +- authMethodContexts: An array of auth method contexts. Each entry will contain the following items: `userId`, `appId`, and `authMethodType`. A list of AUTH_METHOD_TYPEs can be found [here](./overview.md) in the docs. Important to note on Authentication Helpers: authorization is not included. This means that a user can present a Google oAuth JWT as an auth method to be resolved and validated by your Lit Action. The Action will then stick the result inside the Lit.Auth object. In this case, the result would be the users verified google account info like their user id, email address, and more. diff --git a/docs/user-wallets/pkps/advanced-topics/auth-methods/email-sms.md b/docs/user-wallets/pkps/advanced-topics/auth-methods/email-sms.md index e8e9beaf..f1d2bc45 100644 --- a/docs/user-wallets/pkps/advanced-topics/auth-methods/email-sms.md +++ b/docs/user-wallets/pkps/advanced-topics/auth-methods/email-sms.md @@ -60,20 +60,23 @@ const sessionStatus = await client.sessions.authenticate({ }); ``` -## Use an Authenticated Stytch Session with the `lit-auth-client` +## Use an Authenticated Stytch Session with the `LitRelay` ```javascript -import { LitAuthClient } from "@lit-protocol/lit-auth-client"; +import { LIT_NETWORK } from "@lit-protocol/constants"; +import { StytchOtpProvider } from "@lit-protocol/providers"; +import { LitRelay } from "@lit-protocol/lit-auth-client"; -const authClient = new LitAuthClient({ - litRelayConfig: { - relayApiKey: LIT_RELAY_API_KEY, - }, - litNodeClient, +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); -const session = - authClient.initProvider < StytchOtpProvider > ProviderType.StytchOtp; +const session = new StytchOtpProvider({ relay: litRelay, litNodeClient, options: { + userId: sessionStatus.session.user_id, + appId: "project-test-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"} + }); + // from the above example of using the Stytch client to get an authenticated session const authMethod = await session.authenticate({ accessToken: sessionStatus.session_jwt, @@ -86,7 +89,7 @@ We also support specific Stytch `authentication factors` which are the same as u The `user id` will be the `Authentication Factor` transport. Meaning for example of sms otp was the authentication factor, then the phone number of the user will be the `user id` below is a table of what each `auth factor` will use as the `user id` -| ProviderType | user identifier value | +| PROVIDER_TYPE | user identifier value | | ----------------------- | --------------------- | | StytchEmailFactorOtp | email address | | StytchSmsFactorOtp | phone number | @@ -124,9 +127,11 @@ An alternative to minting the PKP NFT via the Lit Relay Server is to send a tran ### Authenticating to Fetch PKP information ```javascript +import { AUTH_METHOD_SCOPE } from "@lit-protocol/constants"; + // Using the session examples above you can call to fetch pkps by the auth method gotten from the provider examples const txHash = await session.fetchPKPThroughRelayer(authMethod, { - permittedAuthMethodScopes: [[AuthMethodScope.SignAnything]] + permittedAuthMethodScopes: [[AUTH_METHOD_SCOPE.SignAnything]] }); ``` @@ -156,6 +161,8 @@ Below is an example of an authentication method from successful authentication After successfully authenticating with a social login provider, you can generate `SessionSigs` using the provider's `getSessionSigs` method. The `getSessionSigs` method takes in an `AuthMethod` object, optional `LitNodeClient` object, a PKP public key, and other session-specific arguments in `SessionSigsParams` object such as `resourceAbilityRequests` and `chain`. View the [API Docs](https://js-sdk.litprotocol.com/interfaces/types_src.BaseProviderSessionSigsParams.html). ```javascript +import { LIT_ABILITY } from "@lit-protocol/constants"; + // Get session signatures for the given PKP public key and auth method const sessionSigs = await provider.getSessionSigs({ authMethod: '', @@ -164,7 +171,7 @@ const sessionSigs = await provider.getSessionSigs({ chain: 'ethereum', resourceAbilityRequests: [{ resource: litResource, - ability: LitAbility.AccessControlConditionDecryption + ability: LIT_ABILITY.AccessControlConditionDecryption } ], }, @@ -187,6 +194,8 @@ Request a specified pkp to sign a session signature, authenticating with an `Aut The `session.fetchPKPThroughRelayer` method above can be used to query PKP public keys associated with a given auth method. You can also use the `contracts-sdk` to query PKP information by Authentication Method. ```javascript +import { LIT_ABILITY } from "@lit-protocol/constants"; + // The implementation below is wrapped by the above `provider.getSessionSigs` const authNeededCallback = async (params: AuthCallbackParams) => { console.log("params", params); @@ -206,7 +215,7 @@ const authNeededCallback = async (params: AuthCallbackParams) => { const resourceAbilities = [ { resource: new LitPkpResource("*"), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ]; const sessionSigs = await litNodeClient diff --git a/docs/user-wallets/pkps/advanced-topics/auth-methods/overview.md b/docs/user-wallets/pkps/advanced-topics/auth-methods/overview.md index 731dd76e..51155b71 100644 --- a/docs/user-wallets/pkps/advanced-topics/auth-methods/overview.md +++ b/docs/user-wallets/pkps/advanced-topics/auth-methods/overview.md @@ -61,20 +61,20 @@ Using this strategy, you could implement your own MFA, where the user must prese **Adding permitted scopes to existing PKPs** 1. Verify the scopes: ```js -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; +import { getAuthIdByAuthMethod } from '@lit-protocol/lit-auth-client'; import { LitContracts } from '@lit-protocol/contracts-sdk'; -import { AuthMethodScope, AuthMethodType } from '@lit-protocol/constants'; +import { AUTH_METHOD_SCOPE, AUTH_METHOD_TYPE } from '@lit-protocol/constants'; const authMethod = { - authMethodType: AuthMethodType.EthWallet, + authMethodType: AUTH_METHOD_TYPE.EthWallet, accessToken: ..., }; -const authId = LitAuthClient.getAuthIdByAuthMethod(authMethod); +const authId = await getAuthIdByAuthMethod(authMethod); const scopes = await contractClient.pkpPermissionsContract.read.getPermittedAuthMethodScopes( tokenId, - AuthMethodType.EthWallet, + AUTH_METHOD_TYPE.EthWallet, authId, 3 // there are only 2 scope numbers atm. and index 0 doesn't count ); @@ -90,23 +90,23 @@ if (scopes[2] !== false) { ``` 2. Set the scopes: ```js -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; +import { getAuthIdByAuthMethod } from '@lit-protocol/lit-auth-client'; import { LitContracts } from '@lit-protocol/contracts-sdk'; -import { AuthMethodScope, AuthMethodType } from '@lit-protocol/constants'; +import { AUTH_METHOD_SCOPE, AUTH_METHOD_TYPE } from '@lit-protocol/constants'; const authMethod = { authMethodType: xx, accessToken: xxx, }; -const authId = LitAuthClient.getAuthIdByAuthMethod(authMethod); +const authId = await getAuthIdByAuthMethod(authMethod); const setScopeTx = await contractClient.pkpPermissionsContract.write.addPermittedAuthMethodScope( tokenId, - AuthMethodType.EthWallet, + AUTH_METHOD_TYPE.EthWallet, authId, - AuthMethodScope.SignAnything + AUTH_METHOD_SCOPE.SignAnything ); await setScopeTx.wait(); diff --git a/docs/user-wallets/pkps/advanced-topics/auth-methods/social-login.md b/docs/user-wallets/pkps/advanced-topics/auth-methods/social-login.md index 2ae82069..a7e25a96 100644 --- a/docs/user-wallets/pkps/advanced-topics/auth-methods/social-login.md +++ b/docs/user-wallets/pkps/advanced-topics/auth-methods/social-login.md @@ -10,55 +10,54 @@ Social login offers users a convenient way to authenticate with Lit Protocol by ## Integrating Social Login -`@lit-protocol/lit-auth-client` makes it easy to implement social login in your web apps. The library provides a `LitAuthClient` class that you can use to initialize a provider for each supported social login method. Each provider has a `signIn()` method that you can call to begin the authentication flow. +`@lit-protocol/lit-auth-client` makes it easy to implement social login in your web apps. The library provides a `LitRelay` class that you can use to initialize a provider for each supported social login method. Each provider has a `signIn()` method that you can call to begin the authentication flow. ```javascript -// Set up LitAuthClient -const litAuthClient = new LitAuthClient({ - litRelayConfig: { - // Request a Lit Relay Server API key here: https://forms.gle/RNZYtGYTY9BcD9MEA - relayApiKey: '', - }, +import { GoogleProvider } from '@lit-protocol/providers'; +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LIT_NETWORK, PROVIDER_TYPE } from '@lit-protocol/constants'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true, + }); +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); // Initialize Google provider -litAuthClient.initProvider(ProviderType.Google, { - // The URL of your web app where users will be redirected after authentication - redirectUri: '', -}); +const googleProvider = new GoogleProvider({ relay, litNodeClient }); // Begin login flow with Google async function authWithGoogle() { - const provider = litAuthClient.getProvider( - ProviderType.Google - ); - await provider.signIn(); + await googleProvider.signIn(); } ``` By default, Lit's social login providers use Lit's OAuth project. In case you want to use a custom OAuth project instead of the one provided by Lit, you can pass a callback in the `signIn` method and modify the URL as needed. ```javascript -// Set up LitAuthClient -const litAuthClient = new LitAuthClient({ - litRelayConfig: { - // Request a Lit Relay Server API key here: https://forms.gle/RNZYtGYTY9BcD9MEA - relayApiKey: '', - }, +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true, + }); +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); // Initialize Google provider -litAuthClient.initProvider(ProviderType.Google, { - // The URL of your web app where users will be redirected after authentication - redirectUri: '', -}); +const googleProvider = new GoogleProvider({ relay, litNodeClient }); // Begin login flow with Google but using your own OAuth project async function authWithGoogle() { - const provider = litAuthClient.getProvider( - ProviderType.Google - ); - await provider.signIn((url) => { + await googleProvider.signIn((url) => { const myURL = new URL(url); // Modify URL as needed @@ -71,30 +70,31 @@ async function authWithGoogle() { } ``` -To login using Discord, you need to initialize the provider with `ProviderType.Discord` and pass it a Discord `clientId` along `redirectUri` +To login using Discord, you need to initialize the provider with `PROVIDER_TYPE.Discord` and pass it a Discord `clientId` along `redirectUri` ```javascript -// Set up LitAuthClient -const litAuthClient = new LitAuthClient({ - litRelayConfig: { - // Request a Lit Relay Server API key here: https://forms.gle/RNZYtGYTY9BcD9MEA - relayApiKey: '', - }, +import { DiscordProvider } from '@lit-protocol/providers'; +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LIT_NETWORK, PROVIDER_TYPE } from '@lit-protocol/constants'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true, + }); +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); // Initialize Discord provider -litAuthClient.initProvider(ProviderType.Discord, { - // The URL of your web app where users will be redirected after authentication - redirectUri: '', - clientId: '', -}); +const discordProvider = new DiscordProvider({ relay, litNodeClient, clientId: '', redirectUri: '' }); // Begin login flow with Discord async function authWithDiscord() { - const provider = litAuthClient.getProvider( - ProviderType.Discord - ); - await provider.signIn((url) => { + await discordProvider.signIn((url) => { const myURL = new URL(url); // Modify URL as needed @@ -125,12 +125,8 @@ import { isSignInRedirect } from '@lit-protocol/lit-auth-client'; async function handleRedirect() { // Check if app has been redirected from Lit login server if (isSignInRedirect(redirectUri)) { - // Get the provider that was used to sign in - const provider = litAuthClient.getProvider( - ProviderType.Google, - ); // Get auth method object that has the OAuth token from redirect callback - const authMethod: AuthMethod = await provider.authenticate(); + const authMethod: AuthMethod = await discordProvider.authenticate(); return authMethod; } } @@ -145,6 +141,8 @@ With the `AuthMethod` object, you can mint or fetch PKPs associated with the aut After successfully authenticating with a social login provider, you can generate `SessionSigs` using the provider's `getSessionSigs` method. The `getSessionSigs` method takes in an `AuthMethod` object, optional `LitNodeClient` object, a PKP public key, and other session-specific arguments in `SessionSigsParams` object such as `resourceAbilityRequests` and `chain`. View the [API Docs](https://js-sdk.litprotocol.com/interfaces/types_src.BaseProviderSessionSigsParams.html). ```javascript +import { LIT_ABILITY } from "@lit-protocol/constants"; + // Get session signatures for the given PKP public key and auth method const sessionSigs = await provider.getSessionSigs({ authMethod: '', @@ -153,7 +151,7 @@ const sessionSigs = await provider.getSessionSigs({ chain: 'ethereum', resourceAbilityRequests: [{ resource: litResource, - ability: LitAbility.AccessControlConditionDecryption + ability: LIT_ABILITY.AccessControlConditionDecryption } ], }, diff --git a/docs/user-wallets/pkps/advanced-topics/auth-methods/web-authn.md b/docs/user-wallets/pkps/advanced-topics/auth-methods/web-authn.md index c6234944..702c0049 100644 --- a/docs/user-wallets/pkps/advanced-topics/auth-methods/web-authn.md +++ b/docs/user-wallets/pkps/advanced-topics/auth-methods/web-authn.md @@ -17,21 +17,28 @@ The `@lit-protocol/lit-auth-client` package leverages the `@simplewebauthn/brows Registration is similar to creating a new account. During the registration process, the user is prompted to create a new public key credential. The public key credential is stored in the smart contract as the new PKP is minted for the user. ```javascript -// Set up LitAuthClient -const litAuthClient = new LitAuthClient({ - litRelayConfig: { - // Request a Lit Relay Server API key here: https://forms.gle/RNZYtGYTY9BcD9MEA - relayApiKey: '', - }, +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { WebAuthnProvider } from '@lit-protocol/providers'; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LIT_NETWORK, PROVIDER_TYPE } from '@lit-protocol/constants'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true, + }); +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); // Initialize WebAuthn provider -litAuthClient.initProvider(ProviderType.WebAuthn); +const webAuthnProvider = new WebAuthnProvider({ relay, litNodeClient }); async function registerWithWebAuthn() { - const provider = litAuthClient.getProvider(ProviderType.WebAuthn); // Register new WebAuthn credential - const options = await provider.register(); + const options = await webAuthnProvider.register(); // Verify registration and mint PKP through relay server const txHash = await provider.verifyAndMintPKPThroughRelayer(options); @@ -69,8 +76,7 @@ Authentication is similar to logging in with an existing account. During the aut ```javascript async function authenticateWithWebAuthn() { - const provider = litAuthClient.getProvider(ProviderType.WebAuthn); - const authMethod = await provider.authenticate(); + const authMethod = await webAuthnProvider.authenticate(); return authMethod; } ``` @@ -82,6 +88,8 @@ The `authenticate` method returns an `AuthMethod` object containing the authenti After successfully authenticating with a social login provider, you can generate `SessionSigs` using the provider's `getSessionSigs` method. The `getSessionSigs` method takes in an `AuthMethod` object, optional `LitNodeClient` object, a PKP public key, and other session-specific arguments in `SessionSigsParams` object such as `resourceAbilityRequests` and `chain`. View the [API Docs](https://js-sdk.litprotocol.com/interfaces/types_src.BaseProviderSessionSigsParams.html). ```javascript +import { LIT_ABILITY } from "@lit-protocol/constants"; + // Get session signatures for the given PKP public key and auth method const sessionSigs = await provider.getSessionSigs({ authMethod: '', @@ -90,7 +98,7 @@ const sessionSigs = await provider.getSessionSigs({ chain: 'ethereum', resourceAbilityRequests: [{ resource: litResource, - ability: LitAbility.AccessControlConditionDecryption + ability: LIT_ABILITY.AccessControlConditionDecryption } ], }, diff --git a/docs/user-wallets/pkps/claimable-keys/usage.md b/docs/user-wallets/pkps/claimable-keys/usage.md index 9ee3b147..30eb3a8c 100644 --- a/docs/user-wallets/pkps/claimable-keys/usage.md +++ b/docs/user-wallets/pkps/claimable-keys/usage.md @@ -41,10 +41,10 @@ An example of claiming with a customized `ClaimProcessor` using the `contracts-s ```jsx import { LitContracts } from '@lit-protocol/contracts-sdk'; import { ClaimRequest, ClaimResult, ClientClaimProcessor } from "@lit-protocol/types" -import { LIT_RPC, LitNetwork } from "@lit-protocol/constants"; +import { LIT_RPC, LIT_NETWORK } from "@lit-protocol/constants"; const client = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false }); await client.connect(); @@ -122,9 +122,9 @@ console.log("pkp public key: ", res.pubkey); ``` -## Examples Using the `LitAuthClient` +## Examples Using the `LitRelay` -### Example of claiming a key with the `LitAuthClient` authenticating with `Stytch` email OTP +### Example of claiming a key with the `LitRelay` authenticating with `Stytch` email OTP We will start by creating an instance of the Stytch client, with your project id and project secret. this should be loaded from a config and never put into source control. @@ -142,7 +142,6 @@ const email = ""; // email address of user const stytchResponse = await client.otps.email.loginOrCreate({ email: email, - }) const authResponse = await client.otps.authenticate({ @@ -160,23 +159,30 @@ const sessionStatus = await client.sessions.authenticate({ }) ``` -Now we can create an instance of the `LitAuthClient` with a `relay API key` . Then an instance of the `stytch otp` provider and provide a `user id` and `app id` the `user id` can come from the `loginOrCreate` response. The `app id` can be found in your `Stytch` project dashboard. +Now we can create an instance of the `LitRelay`. Then an instance of the `StytchOtp` provider and provide a `user id` and `app id` the `user id` can come from the `loginOrCreate` response. The `app id` can be found in your `Stytch` project dashboard. Finally, we can pass the `session jwt` from the `authenticate` response . ```jsx - -const authClient = new LitAuthClient({ - litRelayConfig: { - relayApiKey: "", - } +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { StytchOtpProvider } from '@lit-protocol/providers'; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LIT_NETWORK, PROVIDER_TYPE } from '@lit-protocol/constants'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true, + }); +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); -const session = authClient.initProvider(ProviderType.StytchOtp, { - userId: sessionStatus.session.user_id, - appId: "" -}) +// Initialize StytchOtp provider +const stytchProvider = new StytchOtpProvider({ relay, litNodeClient }); -const authMethod = await session.authenticate({ +const authMethod = await stytchProvider.authenticate({ accessToken: sessionStatus.session_jwt }); @@ -224,26 +230,34 @@ const sessionStatus = await client.sessions.authenticate({ }) ``` -Now we can create an instance of the `LitAuthClient` with a `relay API key` . Then an instance of the `stytch otp` provider and provide a `user id` and `app id` the `user id` can come from the `loginOrCreate` response. The `app id` can be found in your `Stytch` project dashboard. +Now we can create an instance of the `LitRelay`. Then an instance of the `StytchOtp` provider and provide a `user id` and `app id` the `user id` can come from the `loginOrCreate` response. The `app id` can be found in your `Stytch` project dashboard. Finally, we can pass the `session jwt` from the `authenticate` response . Upon successful `authentication` of the token, an `AuthMethod` will be generated. With the `Auth Method` created we can parse it and get an `AuthMethodId` which can be used to calculate the public key. This is because the `AuthMethodId` is the `key id` ```jsx -const authClient = new LitAuthClient({ - litRelayConfig: { - relayApiKey: '', - } +import { LitRelay, getAuthIdByAuthMethod } from '@lit-protocol/lit-auth-client'; +import { StytchOtpProvider } from '@lit-protocol/providers'; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LIT_NETWORK, PROVIDER_TYPE } from '@lit-protocol/constants'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true, + }); +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); -const session = authClient.initProvider(ProviderType.StytchOtp, { - userId: sessionStatus.session.user_id, - appId: "" -}) +// Initialize StytchOtp provider +const stytchProvider = new StytchOtpProvider({ relay, litNodeClient }); -const authMethod = await session.authenticate({ +const authMethod = await stytchProvider.authenticate({ accessToken: sessionStatus.session_jwt }); -const keyId = session.getAuthMethodId({authMethod}); +const keyId = await getAuthIdByAuthMethod(authMethod); const pubkey = session.litNodeClient.computePubkey(keyId); console.log("pkp public key: ", pubkey); diff --git a/docs/user-wallets/pkps/minting/via-contracts.md b/docs/user-wallets/pkps/minting/via-contracts.md index 06dfec31..5e5e7ecd 100644 --- a/docs/user-wallets/pkps/minting/via-contracts.md +++ b/docs/user-wallets/pkps/minting/via-contracts.md @@ -12,8 +12,11 @@ The NFT represents root ownership of the PKP. The NFT owner can grant other user ## Installing the required packages ```bash +yarn add @lit-protocol/lit-node-client yarn add @lit-protocol/lit-auth-client yarn add @lit-protocol/contracts-sdk +yarn add @lit-protocol/constants +yarn add @lit-protocol/providers ``` ## Initializing your `LitContract` instance @@ -28,24 +31,24 @@ await contractClient.connect(); ## Minting a PKP and adding permitted scopes Permitted scopes are a crucial part of defining the capabilities of authentication methods. They determine what actions an authentication method can perform within the system. For instance, the `SignAnything` scope allows an auth method to sign any data, while the `PersonalSign` scope restricts it to signing messages using the EIP-191 scheme. -You can also set scopes: `[]` which will mean that the auth method can only be used for authentication, but not authorization. This means that the auth method can be used to prove that the user is who they say they are, but cannot be used to sign transactions or messages. You can read more about Auth Method scopes [here](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.MintWithAuthParams.html#scopes). +You can also set scopes: `[]` which will mean that the auth method can only be used for authentication, but not authorization. This means that the auth method can be used to prove that the user is who they say they are, but cannot be used to sign transactions or messages. You can read more about Auth Method scopes [here](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.MintWithAuthParams.html#scopes). The following code block demonstrates how to mint a PKP with specific permitted scopes: ```js -import { AuthMethodScope, AuthMethodType } from '@lit-protocol/constants'; +import { AUTH_METHOD_SCOPE, AUTH_METHOD_TYPE } from '@lit-protocol/constants'; const authMethod = { - authMethodType: AuthMethodType.EthWallet, + authMethodType: AUTH_METHOD_TYPE.EthWallet, accessToken: JSON.stringify(authSig), }; const mintInfo = await contractClient.mintWithAuth({ authMethod: authMethod, scopes: [ - // AuthMethodScope.NoPermissions, - AuthMethodScope.SignAnything, - AuthMethodScope.PersonalSign + // AUTH_METHOD_SCOPE.NoPermissions, + AUTH_METHOD_SCOPE.SignAnything, + AUTH_METHOD_SCOPE.PersonalSign ], }); @@ -67,55 +70,75 @@ The relayer is an open source project, and we run one for your use. The source ## Authenticating using `signMessage` Callback If you wish to sign with an ethers wallet type or `signer` you may use the `signMessage` callback to implement a signing callback for the `SIWE` message. ```js -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; -import { AuthMethodScope, AuthMethodType, ProviderType } from '@lit-protocol/constants'; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { AUTH_METHOD_SCOPE, AUTH_METHOD_TYPE, PROVIDER_TYPE, LIT_RPC, LIT_NETWORK } from '@lit-protocol/constants'; +import { EthWalletProvider } from '@lit-protocol/providers'; import * as ethers from 'ethers'; -const provider = new ethers.providers.JsonRpcProvider("your rpc url"); -let wallet = new ethers.Wallet("your wallet private key", provider); -const authProvider = litAuthClient.initProvider(ProviderType.EthWallet); +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true +}) +await litNodeClient.connect(); -let authMethod = authProvider.authenticate({ +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', +}); + +const ethWalletProvider = new EthWalletProvider({ relay: litRelay, litNodeClient }); + +const ethersWallet = new ethers.Wallet( + 'Your Ethereum Private Key', // Replace with your private key + new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE) +); + +const authMethod = await ethWalletProvider.authenticate({ signMessage: (message: string) => { - return await wallet.signMessage(message); + return await ethersWallet.signMessage(message); } }); -// -- setting scope for the auth method -// const options = { - permittedAuthMethodScopes: [[AuthMethodScope.SignAnything]], + permittedAuthMethodScopes: [[AUTH_METHOD_SCOPE.SignAnything]], }; -const mintTx = await authProvider.mintPKPThroughRelayer( - authMethod, - options -); +const mintTx = await litRelay.mintPKPWithAuthMethods([authMethod], options); ``` ## Authenticating using `Web3 Provider` In the case where you wish to generagte a signature from a browser extension wallet (MetaMask, Brave Wallet, etc) you may simply call `authenticate` which calls `checkAndSignAuthMessage`. ```js -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; -import { AuthMethodScope, AuthMethodType, ProviderType } from '@lit-protocol/constants'; -import {Wallet} from 'ethers'; +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { EthWalletProvider } from '@lit-protocol/providers'; +import { AUTH_METHOD_SCOPE, AUTH_METHOD_TYPE, PROVIDER_TYPE } from '@lit-protocol/constants'; +import { Wallet } from 'ethers'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true +}) +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', +}); -const authProvider = litAuthClient.initProvider(ProviderType.EthWallet); +const ethWalletProvider = new EthWalletProvider({ relay: litRelay, litNodeClient }); -// Will call `checkAndSignAuthMessage({chain: ethereum})` -let authMethod = await authProvider.authenticate({chain: "ethereum"}); +const authMethod = await authProvider.authenticate({chain: "ethereum"}); // -- setting scope for the auth method // const options = { - permittedAuthMethodScopes: [[AuthMethodScope.SignAnything]], + permittedAuthMethodScopes: [[AUTH_METHOD_SCOPE.SignAnything]], }; -const mintTx = await authProvider.mintPKPThroughRelayer( - authMethod, - options -); +const mintTx = await litRelay.mintPKPWithAuthMethods([authMethod], options); ``` diff --git a/docs/user-wallets/pkps/minting/via-multiple-auth-methods.md b/docs/user-wallets/pkps/minting/via-multiple-auth-methods.md index 0293c711..e4bf8e1a 100644 --- a/docs/user-wallets/pkps/minting/via-multiple-auth-methods.md +++ b/docs/user-wallets/pkps/minting/via-multiple-auth-methods.md @@ -2,16 +2,16 @@ import FeedbackComponent from "@site/src/pages/feedback.md"; # Mint via multiple Auth Methods You can also mint a PKP using [multiple Auth Methods](../advanced-topics/auth-methods/overview.md) (i.e. Multi-Factor Authentication). This can be done in two different ways: -1. [Using `LitAuthClient`](#using-litauthclient) +1. [Using `LitRelay`](#using-litrelay) 2. [Using `ContractsSDK`](#using-contractssdk) -## Using `LitAuthClient` +## Using `LitRelay` In this section, we will demonstrate how to mint a PKP using two popular authentication methods: 1. Google OAuth Login, and 2. Stytch SMS (OTP) -via `LitAuthClient`. This approach enhances security by requiring authentication through both a social login provider and a one-time password sent via SMS. You can mint a PKP using Google OAuth token and a generated token from sucessful OTP code confirmation, by following these steps: +via `LitRelay`. This approach enhances security by requiring authentication through both a social login provider and a one-time password sent via SMS. You can mint a PKP using Google OAuth token and a generated token from sucessful OTP code confirmation, by following these steps: ### Installing the `LitAuthClient` package ```bash @@ -20,33 +20,30 @@ yarn add @lit-protocol/lit-auth-client ### Integrating Google OAuth Login -`@lit-protocol/lit-auth-client` makes it easy to implement social login in your web apps. The library provides a `LitAuthClient` class that you can use to initialize a provider for each supported social login method. Each provider has a `signIn()` method that you can call to begin the authentication flow. +`@lit-protocol/lit-auth-client` makes it easy to implement social login in your web apps. The library provides a `LitRelay` class that you can use to initialize a provider for each supported social login method. Each provider has a `signIn()` method that you can call to begin the authentication flow. ```javascript -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; -import { ProviderType } from '@lit-protocol/constants'; - -// Set up LitAuthClient -const litAuthClient = new LitAuthClient({ - litRelayConfig: { - // Request a Lit Relay Server API key here: https://forms.gle/RNZYtGYTY9BcD9MEA - relayApiKey: '', - }, +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { GoogleProvider } from '@lit-protocol/providers'; +import { AUTH_METHOD_SCOPE, AUTH_METHOD_TYPE, PROVIDER_TYPE } from '@lit-protocol/constants'; +import { Wallet } from 'ethers'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true +}) +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); // Initialize Google provider -litAuthClient.initProvider(ProviderType.Google, { - // The URL of your web app where users will be redirected after authentication - redirectUri: '', -}); +const googleProvider = new GoogleProvider({ relay: litRelay, litNodeClient }); -// Begin login flow with Google -async function authWithGoogle() { - const provider = litAuthClient.getProvider( - ProviderType.Google - ); - await provider.signIn(); -} +await googleProvider.signIn(); ``` :::note @@ -62,18 +59,14 @@ If you are using Lit Relay Server, you will need to request an API key [here](ht At the `redirectUri` specified when initializing the providers, call `handleSignInRedirect`. You can also use `isSignInRedirect` method to check if the app is in the redirect state or not. ```javascript -import { LitAuthClient, isSignInRedirect } from '@lit-protocol/lit-auth-client'; -import { AuthMethodScope, ProviderType } from '@lit-protocol/constants'; +import { LitRelay, isSignInRedirect } from '@lit-protocol/lit-auth-client'; +import { AUTH_METHOD_SCOPE, PROVIDER_TYPE } from '@lit-protocol/constants'; async function handleRedirect() { // Check if app has been redirected from Lit login server if (isSignInRedirect(redirectUri)) { - // Get the provider that was used to sign in - const provider = provider = litAuthClient.getProvider( - ProviderType.Google, - ); // Get auth method object that has the OAuth token from redirect callback - const authMethodGoogle: AuthMethod = await provider.authenticate(); + const authMethodGoogle: AuthMethod = await googleProvider.authenticate(); return authMethodGoogle; } } @@ -86,17 +79,24 @@ The provider's `authenticate` method validates the URL parameters returned from You can also authenticate users using SMS (OTP) by sending a one-time passcode to their phone number. This can be done using the `Stytch` provider. ```javascript -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; -import { AuthMethodScope, ProviderType } from '@lit-protocol/constants'; - -// Set up LitAuthClient -const litAuthClient = new LitAuthClient({ - litRelayConfig: { - // Request a Lit Relay Server API key here: https://forms.gle/RNZYtGYTY9BcD9MEA - relayApiKey: '', - }, +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { StytchOtpProvider } from '@lit-protocol/providers'; +import { AUTH_METHOD_SCOPE, PROVIDER_TYPE, LIT_NETWORK } from '@lit-protocol/constants'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true +}) +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); +const stytchOtpProvider = new StytchOtpProvider({ relay: litRelay, litNodeClient }); + // Send one-time passcodes via phone number through Stytch async function sendPasscode(userId) { // userId: phone number @@ -121,55 +121,25 @@ async function authenticateWithStytch(code, methodId) { session_duration_minutes: 60, }); - // Initialize StytchSmsFactorOtp provider - const provider = litAuthClient.initProvider(ProviderType.StytchSmsFactorOtp, { - appId: YOUR_STYTCH_PROJECT_ID - }); - // Get auth method object after autheticating Stytch JWT - const authMethodSMS = await provider.authenticate({ response.session_jwt, response.user_id }); + const authMethodSMS = await stytchOtpProvider.authenticate({ response.session_jwt, response.user_id }); return authMethodSMS; } ``` ### Mint PKP with Multiple Auth Methods -Once you have authenticated the user with both Google OAuth Login and SMS (OTP), you can proceed to mint a PKP using both Auth Methods. +Once you have authenticated the user with both Google OAuth Login and SMS (OTP), you can proceed to mint a PKP using both Auth Methods. This can be done with the `LitRelay` class: ```javascript -async function mintPKPWithMultipleAuthMethods(authMethodGoogle, authMethodSMS) { - let authClient = new LitAuthClient({ - litRelayConfig: { - relayApiKey: '', - }, - }); - - // Mint PKP using both Auth Methods - let res = await authClient.mintPKPWithAuthMethods( - [authMethodGoogle, authMethodSMS], // Auth Methods - { - pkpPermissionScopes: [[1], [1]], // PKP Permission Scopes - sendPkpToitself: true, // whether to send PKP to itself or not - addPkpEthAddressAsPermittedAddress: true, // whether to add PKP eth address as permitted address or not - } - ); - - if (typeof res != 'object') { - console.error('Minting failed'); - return; - } - - console.log('Minting successful', res); - return res; -} +const pkp = await litRelay.mintPKPWithAuthMethods(authMethods, options); ``` - ## Using `ContractsSDK` You can also mint a PKP using multiple Auth Methods via `ContractsSDK` by following these steps: -### Installing the `LitAuthClient` package +### Installing the `LitContracts` package ```bash yarn add @lit-protocol/lit-auth-client yarn add @lit-protocol/contracts-sdk @@ -181,11 +151,16 @@ First, configure your Ethereum provider and the controller wallet. Initialize th ```javascript import { LitContracts } from '@lit-protocol/contracts-sdk'; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; + +const ethersWallet = new ethers.Wallet( + 'Your Ethereum Private Key', // Replace with your private key + new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE) +); const contractClient = new LitContracts({ - signer: controllerWallet, // Your ethers wallet - network: LitNetwork.DatilTest, + signer: ethersWallet, + network: LIT_NETWORK.DatilTest, }); await contractClient.connect(); @@ -195,12 +170,14 @@ await contractClient.connect(); Define the auth method you intend to use for minting the PKP. This example uses an Ethereum wallet's authentication signature, but you can adapt this to include other methods such as OAuth tokens from social logins or OTP codes from email/SMS verification. ```javascript +import { getAuthIdByAuthMethod } from '@lit-protocol/lit-auth-client'; + const authMethodWallet = { authMethodType: 1, // Adjust based on the auth method accessToken: JSON.stringify(authSig), // Use authSig obtained from the controller wallet }; -const authIdWallet = LitAuthClient.getAuthIdByAuthMethod(authMethodWallet); +const authIdWallet = await getAuthIdByAuthMethod(authMethodWallet); const authIdAction = contractClient.utils.getBytesFromMultihash(''); ``` @@ -216,7 +193,7 @@ const mintCost = await contractClient.pkpNftContract.read.mintCost(); // Mint PKP using both Auth Methods const mintTx = await contractClient.pkpHelperContract.write.mintNextAndAddAuthMethods( 2, // key type - [AuthMethodType.EthWallet, AuthMethodType.LitAction], // Specify the auth method types + [AUTH_METHOD_TYPE.EthWallet, AUTH_METHOD_TYPE.LitAction], // Specify the auth method types [authIdWallet, authIdAction], // Specify the auth method IDs ['0x', '0x'], // Specify the auth method public keys [[1], [1]], // Specify the auth method scopes diff --git a/docs/user-wallets/pkps/minting/via-social.md b/docs/user-wallets/pkps/minting/via-social.md index a34eb628..54e93445 100644 --- a/docs/user-wallets/pkps/minting/via-social.md +++ b/docs/user-wallets/pkps/minting/via-social.md @@ -11,37 +11,34 @@ You can mint PKPs using Google OAuth tokens by following these steps: ### Installing the `LitAuthClient` package ```bash yarn add @lit-protocol/lit-auth-client +yarn add @lit-protocol/providers ``` ### Integrating Social Login -`@lit-protocol/lit-auth-client` makes it easy to implement social login in your web apps. The library provides a `LitAuthClient` class that you can use to initialize a provider for each supported social login method. Each provider has a `signIn()` method that you can call to begin the authentication flow. +`@lit-protocol/lit-auth-client` makes it easy to implement social login in your web apps. The library provides a `LitRelay` class that you can use to initialize a provider. The specific providers will be in the `@lit-protocol/providers` package. Each provider has a `signIn()` method that you can call to begin the authentication flow. ```javascript -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; -import { ProviderType } from '@lit-protocol/constants'; - -// Set up LitAuthClient -const litAuthClient = new LitAuthClient({ - litRelayConfig: { - // Request a Lit Relay Server API key here: https://forms.gle/RNZYtGYTY9BcD9MEA - relayApiKey: '', - }, +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { StytchOtpProvider } from '@lit-protocol/providers'; +import { PROVIDER_TYPE, LIT_NETWORK } from '@lit-protocol/constants'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true, }); +await litNodeClient.connect(); -// Initialize Google provider -litAuthClient.initProvider(ProviderType.Google, { - // The URL of your web app where users will be redirected after authentication - redirectUri: '', +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); +const googleProvider = new GoogleProvider({ relay: litRelay, litNodeClient }); + // Begin login flow with Google -async function authWithGoogle() { - const provider = litAuthClient.getProvider( - ProviderType.Google - ); - await provider.signIn(); -} +await googleProvider.signIn(); ``` :::note @@ -57,30 +54,26 @@ If you are using Lit Relay Server, you will need to request an API key [here](ht At the `redirectUri` specified when initializing the providers, call `handleSignInRedirect`. You can also use `isSignInRedirect` method to check if the app is in the redirect state or not. ```javascript -import { LitAuthClient, isSignInRedirect } from '@lit-protocol/lit-auth-client'; -import { AuthMethodScope, ProviderType } from '@lit-protocol/constants'; +import { LitRelay, isSignInRedirect } from '@lit-protocol/lit-auth-client'; +import { AUTH_METHOD_SCOPE, PROVIDER_TYPE } from '@lit-protocol/constants'; async function handleRedirect() { // Check if app has been redirected from Lit login server if (isSignInRedirect(redirectUri)) { - // Get the provider that was used to sign in - const provider = provider = litAuthClient.getProvider( - ProviderType.Google, - ); // Get auth method object that has the OAuth token from redirect callback - const authMethod: AuthMethod = await provider.authenticate(); + const authMethod: AuthMethod = await googleProvider.authenticate(); // -- setting scope for the auth method // const options = { - permittedAuthMethodScopes: [[AuthMethodScope.SignAnything]], + permittedAuthMethodScopes: [[AUTH_METHOD_SCOPE.SignAnything]], }; // Mint PKP using the auth method - const mintTx = await provider.mintPKPThroughRelayer( - authMethod, + const mintTx = await googleProvider.mintPKPWithAuthMethods( + [authMethod], options ); // Fetch PKPs associated with the authenticated social account - const pkps = await provider.fetchPKPsThroughRelayer(authMethod); + const pkps = await googleProvider.getPKPsForAuthMethod(authMethod); return pkps; } } @@ -95,6 +88,8 @@ With the `AuthMethod` object, you can mint and fetch PKPs associated with the au After successfully authenticating with a social login provider, you can generate `SessionSigs` using the provider's `getSessionSigs` method. The `getSessionSigs` method takes in an `AuthMethod` object, optional `LitNodeClient` object, a PKP public key, and other session-specific arguments in `SessionSigsParams` object such as `resourceAbilityRequests` and `chain`. View the [API Docs](https://js-sdk.litprotocol.com/interfaces/types_src.BaseProviderSessionSigsParams.html). ```javascript +import { LIT_ABILITY } from "@lit-protocol/constants"; + // Get session signatures for the given PKP public key and auth method const sessionSigs = await provider.getSessionSigs({ authMethod: '', @@ -103,7 +98,7 @@ const sessionSigs = await provider.getSessionSigs({ chain: 'ethereum', resourceAbilityRequests: [{ resource: litResource, - ability: LitAbility.AccessControlConditionDecryption + ability: LIT_ABILITY.AccessControlConditionDecryption } ], }, @@ -116,15 +111,20 @@ const sessionSigs = await provider.getSessionSigs({ You can also mint a PKP by presenting a generated token from sucessful OTP code confirmation, which will be returned by the `lit-auth-client` in the `AuthMethod` return from successful code confirmation. ```javascript -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; -import { AuthMethodScope, ProviderType } from '@lit-protocol/constants'; - -// Set up LitAuthClient -const litAuthClient = new LitAuthClient({ - litRelayConfig: { - // Request a Lit Relay Server API key here: https://forms.gle/RNZYtGYTY9BcD9MEA - relayApiKey: '', - }, +import { LitNodeClient } from '@lit-protocol/lit-node-client'; +import { LitRelay } from '@lit-protocol/lit-auth-client'; +import { LIT_NETWORK, PROVIDER_TYPE } from '@lit-protocol/constants'; +import { StytchOtpProvider } from '@lit-protocol/providers'; + +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: true +}) +await litNodeClient.connect(); + +const litRelay = new LitRelay({ + relayUrl: LitRelay.getRelayUrl(LIT_NETWORK.DatilDev), + relayApiKey: 'test-api-key', }); // Send one-time passcodes via email or phone number through Stytch @@ -151,32 +151,24 @@ async function authenticateWithStytch(method, code, methodId) { }); // Initialize StytchEmailFactorOtp or StytchSmsFactorOtp provider - let provider; - if (method === "email") { - provider = litAuthClient.initProvider(ProviderType.StytchEmailFactorOtp, { - appId: YOUR_STYTCH_PROJECT_ID, - }); - } else { - provider = litAuthClient.initProvider(ProviderType.StytchSmsFactorOtp, { - appId: YOUR_STYTCH_PROJECT_ID - }); - } + const stytchOtpProvider = new StytchOtpProvider({ relay: litRelay, litNodeClient }); + // Get auth method object after autheticating Stytch JWT - const authMethod = await provider.authenticate({ response.session_jwt, response.user_id }); + const authMethod = await stytchOtpProvider.authenticate({ response.session_jwt, response.user_id }); // -- setting scope for the auth method // const options = { - permittedAuthMethodScopes: [[AuthMethodScope.SignAnything]], + permittedAuthMethodScopes: [[AUTH_METHOD_SCOPE.SignAnything]], }; // Mint PKP using the auth method - const mintTx = await provider.mintPKPThroughRelayer( - authMethod, + const mintTx = await stytchOtpProvider.mintPKPWithAuthMethods( + [authMethod], options ); // Fetch PKPs associated with the authenticated social account - const pkps = await provider.fetchPKPsThroughRelayer(authMethod); + const pkps = await stytchOtpProvider.getPKPsForAuthMethod(authMethod); return pkps; } ``` diff --git a/docs/user-wallets/pkps/quick-start.md b/docs/user-wallets/pkps/quick-start.md index 3a5e5b3a..49bb0ad3 100644 --- a/docs/user-wallets/pkps/quick-start.md +++ b/docs/user-wallets/pkps/quick-start.md @@ -52,10 +52,10 @@ Within a file (in the Lit example repos it will likely be called `lit.js`), set `client.connect()` will return a promise that resolves when you are connected to the Lit Network. ```jsx -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const client = new LitJsSdk.LitNodeClient({ - litNetwork: LitNetwork.Datil, + litNetwork: LIT_NETWORK.Datil, }); await client.connect(); @@ -82,11 +82,11 @@ Keep in mind that in the server-side implementation, the client class is named  `app.locals.litNodeClient.connect()` returns a promise that resolves when you are connected to the Lit network. ```jsx -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; app.locals.litNodeClient = new LitJsSdk.LitNodeClientNodeJs({ alertWhenUnauthorized: false, - litNetwork: LitNetwork.Datil, + litNetwork: LIT_NETWORK.Datil, }); await app.locals.litNodeClient.connect(); ``` @@ -116,11 +116,11 @@ You'll need to use ethers.js v5 with the Lit SDK. The Lit SDK is not compatible ```jsx import { LitContracts } from '@lit-protocol/contracts-sdk'; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const contractClient = new LitContracts({ signer: wallet, - network: LitNetwork.Datil, + network: LIT_NETWORK.Datil, }); await contractClient.connect(); @@ -139,10 +139,9 @@ In order to interact with the nodes in the Lit Network, you will need to generat Using the Lit SDK and the methods `createSiweMessageWithRecaps` and `generateAuthSig` from the `@lit-protocol/auth-helpers` package, we can create a `SessionSigs` by signing a SIWE message using a private key stored in a browser wallet like MetaMask: ```jsx -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK, LIT_ABILITY } from "@lit-protocol/constants"; import { LitNodeClient } from "@lit-protocol/lit-node-client"; import { - LitAbility, LitAccessControlConditionResource, createSiweMessage, generateAuthSig, @@ -154,7 +153,7 @@ await provider.send("eth_requestAccounts", []); const ethersSigner = provider.getSigner(); const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.Datil, + litNetwork: LIT_NETWORK.Datil, }); await litNodeClient.connect(); @@ -164,7 +163,7 @@ const sessionSigs = await litNodeClient.getSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], authNeededCallback: async ({ resourceAbilityRequests, expiration, uri }) => { @@ -268,7 +267,7 @@ const authNeededCallback = async (params) => { const resourceAbilities = [ { resource: new LitActionResource('*'), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ]; // Get the session key for the session signing request @@ -291,7 +290,7 @@ Now that we have installed all of the required packages and authenticated with t Permitted scopes are a crucial part of defining the capabilities of each authentication method you use. They determine what actions a given authentication method can perform with the PKP. For instance, the `SignAnything` scope allows an auth method to sign any data, while the `PersonalSign` scope restricts it to signing messages using the EIP-191 scheme. -You can also set scopes: `[]` which will mean that the auth method can only be used for authentication, but not authorization. This means that the auth method can be used to prove that the user is who they say they are, but cannot be used to sign transactions or messages. You can read more about Auth Method scopes [here](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.MintWithAuthParams.html#scopes). +You can also set scopes: `[]` which will mean that the auth method can only be used for authentication, but not authorization. This means that the auth method can be used to prove that the user is who they say they are, but cannot be used to sign transactions or messages. You can read more about Auth Method scopes [here](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.MintWithAuthParams.html#scopes). The following code block demonstrates how to mint a PKP with specific permitted scopes: @@ -300,19 +299,19 @@ The PKP NFT represents root ownership of the key pair. The NFT owner can grant o ::: ```jsx -import { AuthMethodScope, AuthMethodType } from '@lit-protocol/constants'; +import { AUTH_METHOD_SCOPE, AUTH_METHOD_TYPE } from '@lit-protocol/constants'; const authMethod = { - authMethodType: AuthMethodType.EthWallet, + authMethodType: AUTH_METHOD_TYPE.EthWallet, accessToken: JSON.stringify(authSig), }; const mintInfo = await contractClient.mintWithAuth({ authMethod: authMethod, scopes: [ - // AuthMethodScope.NoPermissions, - AuthMethodScope.SignAnything, - AuthMethodScope.PersonalSign + // AUTH_METHOD_SCOPE.NoPermissions, + AUTH_METHOD_SCOPE.SignAnything, + AUTH_METHOD_SCOPE.PersonalSign ], }); @@ -330,12 +329,12 @@ const mintInfo = await contractClient.mintWithAuth({ You should now have successfully minted a PKP! You can verify that the PKP has the necessary permissions for signing by calling the following function: ```jsx -import { LitAuthClient } from '@lit-protocol/lit-auth-client'; +import { getAuthIdByAuthMethod } from '@lit-protocol/lit-auth-client'; -const authId = await LitAuthClient.getAuthIdByAuthMethod(authMethod); +const authId = await getAuthIdByAuthMethod(authMethod); await contractClient.pkpPermissionsContract.read.getPermittedAuthMethodScopes( mintInfo.pkp.tokenId, - AuthMethodType.EthWallet, + AUTH_METHOD_TYPE.EthWallet, authId, 3 ); @@ -357,13 +356,13 @@ In order to execute a transaction with Lit, you’ll need to reserve capacity on The first step is to initialize a signer. This should be a wallet controlled by your application and the same wallet you’ll use to mint the Capacity Credit NFT: ```jsx -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const walletWithCapacityCredit = new Wallet(""); let contractClient = new LitContracts({ signer: dAppOwnerWallet, - network: LitNetwork.Datil, + network: LIT_NETWORK.Datil, }); await contractClient.connect(); @@ -467,7 +466,7 @@ We can use the Capacity Credit delegation to generate a Session Signature for th resourceAbilityRequests: [ { resource: new LitPKPResource('*'), - ability: LitAbility.PKPSigning, + ability: LIT_ABILITY.PKPSigning, }, ], authNeededCallback: pkpAuthNeededCallback, diff --git a/docs/user-wallets/pkps/walletconnect.md b/docs/user-wallets/pkps/walletconnect.md index 9da8bdd6..44d0d7f7 100644 --- a/docs/user-wallets/pkps/walletconnect.md +++ b/docs/user-wallets/pkps/walletconnect.md @@ -4,74 +4,92 @@ import FeedbackComponent from "@site/src/pages/feedback.md"; Leverage Lit Protocol and WalletConnect V2 to seamlessly connect PKPs to hundreds of dApps. WalletConnect enables secure communication between wallets and dApps through QR code scanning and deep linking. With WalletConnect, PKPs act as MPC wallets, interacting with dApps without ever exposing private keys. -To connect a PKP and a dApp, you will need to: +This guide will show you how to implement this for an Ethereum wallet. If you'd like to do the same for [Sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) with `PKPSuiWallet` or [Cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) with `PKPCosmosWallet`. -1. Create a `PKPClient` -2. Initialize `PKPWalletConnect` with the `PKPClient` -3. Subscribe and respond to events +Please note that this example requires you install the `@walletconnect/web3wallet` package. ## 1. Create a `PKPClient` -`PKPClient` represents a PKP and initializes signers for use across multiple blockchains (note: EVM-only at the moment). +Connecting a PKP to a dApp requires: + +1. Creation of a `PKPEthersWallet` +2. Initialization of `PKPWalletConnect` using the `PKPEthersWallet` +3. Subscribing and responding to events ```js import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitAbility, LitActionResource } from '@lit-protocol/auth-helpers'; -import { PKPClient } from "@lit-protocol/pkp-client"; +import { LIT_NETWORK, LIT_ABILITY, LIT_RPC } from "@lit-protocol/constants"; +import { + createSiweMessage, + generateAuthSig, + LitPKPResource +} from "@lit-protocol/auth-helpers"; +import { PKPEthersWallet } from "@lit-protocol/pkp-ethers"; +import { PKPWalletConnect } from "@lit-protocol/pkp-walletconnect"; +import * as ethers from "ethers"; -// If you haven't done before, create a LitNodeClient instance -const litNodeClient = new LitNodeClient({ - litNetwork: "datil-dev", -}); -await litNodeClient.connect(); +const ETHEREUM_PRIVATE_KEY = ""; +const LIT_PKP_PUBLIC_KEY = ""; -// Prepare needed params for authContext -const resourceAbilities = [ - { - resource: new LitActionResource("*"), - ability: LitAbility.PKPSigning, - }, -]; - -const authNeededCallback = async (params: AuthCallbackParams) => { - const response = await litNodeClient.signSessionKey({ - statement: params.statement, - authMethods: [authMethod], - expiration: params.expiration, - resources: params.resources, - chainId: 1, - }); - return response.authSig; -}; +const ethersWallet = new ethers.Wallet( + ETHEREUM_PRIVATE_KEY, + new ethers.providers.JsonRpcProvider(LIT_RPC.CHRONICLE_YELLOWSTONE) +); -const pkpClient = new PKPClient({ - authContext: { - client: litNodeClient, - getSessionSigsProps: { - chain: 'ethereum', - expiration: new Date(Date.now() + 60_000 * 60).toISOString(), - resourceAbilityRequests: resourceAbilities, - authNeededCallback, +const litNodeClient = new LitNodeClient({ + litNetwork: LIT_NETWORK.DatilDev, + debug: false, + }); + await litNodeClient.connect(); + +const sessionSignatures = await litNodeClient.getSessionSigs({ + chain: "ethereum", + expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes + resourceAbilityRequests: [ + { + resource: new LitPKPResource("*"), + ability: LIT_ABILITY.PKPSigning, }, + ], + authNeededCallback: async ({ + uri, + expiration, + resourceAbilityRequests, + }) => { + const toSign = await createSiweMessage({ + uri, + expiration, + resources: resourceAbilityRequests, + walletAddress: await ethersWallet.getAddress(), + nonce: await litNodeClient.getLatestBlockhash(), + litNodeClient, + }); + + return await generateAuthSig({ + signer: ethersWallet, + toSign, + }); }, - // controllerAuthSig: authSig, - // controllerSessionSigs: sesionSigs, // (deprecated) - pkpPubKey: "", }); -await pkpClient.connect(); -``` -The `getSessionSigsProps`, `controllerAuthSig` or `controllerSessionSigs` (this last one deprecated) are used to authorize requests to the Lit nodes. To learn how to leverage different authentication methods, refer to the [Authentication section](./advanced-topics/auth-methods/overview). +const pkpEthersWallet = new PKPEthersWallet({ + litNodeClient, + pkpPubKey: LIT_PKP_PUBLIC_KEY!, + controllerSessionSigs: sessionSignatures +}); + + +const pkpWalletConnect = new PKPWalletConnect(); +pkpWalletConnect.addPKPEthersWallet(pkpEthersWallet); +``` -To view more constructor options, refer to the [API docs](https://js-sdk.litprotocol.com/interfaces/types_src.PKPClientProp.html). +The `authContext` or `controllerSessionSigs` are used to authorize requests to the Lit nodes. The only difference between these methods are that `controllerSessionSigs` accepts the Session Signatures object, while `authContext` accepts the same properties that Session Signatures do during creation. Those properties can be found [here](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.AuthenticationProps.html#getSessionSigsProps). ## 2. Initialize `PKPWalletConnect` with the `PKPClient` `PKPWalletConnect` wraps [`@walletconnect/web3wallet`](https://www.npmjs.com/package/@walletconnect/web3wallet) to manage WalletConnect session proposals and requests using the given PKPClient. ```js -import { PKPWalletConnect } from "@lit-protocol/pkp-walletconnect"; - const config = { projectId: "", metadata: { @@ -81,9 +99,8 @@ const config = { icons: ["https://litprotocol.com/favicon.png"], }, }; -const wcClient = new PKPWalletConnect(); -await wcClient.initWalletConnect(config); -wcClient.addPKPClient(pkpWallet); + +await pkpWalletConnect.initWalletConnect(config); ``` ## 3. Subscribe and respond to events diff --git a/docs/user-wallets/wrapped-keys/custom-wrapped-keys.md b/docs/user-wallets/wrapped-keys/custom-wrapped-keys.md index 73004554..4e2919e4 100644 --- a/docs/user-wallets/wrapped-keys/custom-wrapped-keys.md +++ b/docs/user-wallets/wrapped-keys/custom-wrapped-keys.md @@ -19,22 +19,22 @@ Currently the Wrapped Keys SDK includes Lit Action to support the following: For Wrapped Keys derived from the `K256` algorithm (commonly known as `ecdsa`): - Generating `K256` (commonly known as `ecdsa`) private keys within a Lit Action - - Uses the [generateEncryptedEthereumPrivateKey](https://v6-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#generateEncryptedEthereumPrivateKey) Lit Action + - Uses the [generateEncryptedEthereumPrivateKey](https://v7-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#generateEncryptedEthereumPrivateKey) Lit Action - Signing arbitrary messages using Ethers.js' [signMessage](https://docs.ethers.org/v5/api/signer/#Signer-signMessage) - - Uses the [signMessageWithEthereumEncryptedKey](https://v6-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signMessageWithEthereumEncryptedKey) Lit Action + - Uses the [signMessageWithEthereumEncryptedKey](https://v7-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signMessageWithEthereumEncryptedKey) Lit Action - Signing Ethers.js transaction objects using [signTransaction](https://docs.ethers.org/v5/api/signer/#Signer-signTransaction) - - Uses the [signTransactionWithEthereumEncryptedKey](https://v6-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signTransactionWithEthereumEncryptedKey) Lit Action + - Uses the [signTransactionWithEthereumEncryptedKey](https://v7-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signTransactionWithEthereumEncryptedKey) Lit Action ### Wrapped Keys Derived `ed25519` Algorithm For Wrapped Keys derived from the `ed25519` algorithm (used for Solana private key): - Generating `ed25519` private keys within a Lit Action using the [@solana/web3.js](https://github.com/solana-labs/solana-web3.js) SDK - - Uses the [generateEncryptedSolanaPrivateKey](https://v6-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signTransactionWithEthereumEncryptedKey) Lit Action + - Uses the [generateEncryptedSolanaPrivateKey](https://v7-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signTransactionWithEthereumEncryptedKey) Lit Action - Signing arbitrary messages using the `@solana/web3.js` SDK - - Uses the [signMessageWithSolanaEncryptedKey](https://v6-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signTransactionWithEthereumEncryptedKey) Lit Action + - Uses the [signMessageWithSolanaEncryptedKey](https://v7-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signTransactionWithEthereumEncryptedKey) Lit Action - Signing Solana transaction objects using the `@solana/web3.js` SDK - - uses the [signTransactionWithSolanaEncryptedKey](https://v6-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signTransactionWithEthereumEncryptedKey) Lit Action + - uses the [signTransactionWithSolanaEncryptedKey](https://v7-api-doc-lit-js-sdk.vercel.app/modules/wrapped_keys_lit_actions_src.html#signTransactionWithEthereumEncryptedKey) Lit Action ## Implementing a Custom Lit Action @@ -155,11 +155,11 @@ If you manually encrypted your private key with custom Access Control Conditions ##### `ciphertext` -This is the encrypted form of the underlying private key for the Wrapped Key (encrypted using the Lit network's BLS public key). This value is returned by the encryption functions from the Lit SDK e.g. [encryptString](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html). +This is the encrypted form of the underlying private key for the Wrapped Key (encrypted using the Lit network's BLS public key). This value is returned by the encryption functions from the Lit SDK e.g. [encryptString](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html). ##### `dataToEncryptHash` -This is the `SHA-256` hash of the underlying private key for the Wrapped Key that was encrypted using the Lit network's BLS public key. This value is returned by the encryption functions from the Lit SDK e.g. [encryptString](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html). +This is the `SHA-256` hash of the underlying private key for the Wrapped Key that was encrypted using the Lit network's BLS public key. This value is returned by the encryption functions from the Lit SDK e.g. [encryptString](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html). ##### `authSig` @@ -216,7 +216,7 @@ After decrypting the private key, you'll have access to it's clear text form to ## Executing Your Custom Lit Action -After implementing your custom Lit Action, you'll want to make use of Lit SDK's [executeJs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#executeJs) method to execute the Lit Action with any required arguments. +After implementing your custom Lit Action, you'll want to make use of Lit SDK's [executeJs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#executeJs) method to execute the Lit Action with any required arguments. As a reference implementation, you can take a look at the following methods used by the Wrapped Keys SDK to call the [Provided Wrapped Keys Lit Actions](#provided-wrapped-keys-lit-actions): diff --git a/docs/user-wallets/wrapped-keys/exporting-wrapped-key.md b/docs/user-wallets/wrapped-keys/exporting-wrapped-key.md index 1cb4af7c..b92acdc9 100644 --- a/docs/user-wallets/wrapped-keys/exporting-wrapped-key.md +++ b/docs/user-wallets/wrapped-keys/exporting-wrapped-key.md @@ -74,11 +74,11 @@ When a Wrapped Key is generated, it's encrypted with the following [Access Contr where `pkpAddress` is the addressed derived from the `pkpSessionSigs`. This restricts the decryption of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which generated the Wrapped Key. -A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. +A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. #### `litNodeClient` -This is an instance of the [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. +This is an instance of the [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. #### `network` @@ -227,10 +227,10 @@ Here we are instantiating an instance of `LitNodeClient` and connecting it to th ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -252,8 +252,8 @@ The Auth Method used in this example implementation is signing a Sign in With Et ```ts import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -270,7 +270,7 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes diff --git a/docs/user-wallets/wrapped-keys/generating-wrapped-key.md b/docs/user-wallets/wrapped-keys/generating-wrapped-key.md index 4258c28f..67bb8b38 100644 --- a/docs/user-wallets/wrapped-keys/generating-wrapped-key.md +++ b/docs/user-wallets/wrapped-keys/generating-wrapped-key.md @@ -24,7 +24,7 @@ Below we will walk through an implementation of `generatePrivateKey`. The full c 5. The generated private key is then encrypted using the previously generated Access Control Conditions 6. The encryption metadata is returned from the Lit Action 7. The Wrapped Keys SDK then stores the private key encryption metadata to the Wrapped Keys backend service, associating it with the PKP's Ethereum address -8. The SDK returns a [GeneratePrivateKeyResult](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/wrapped_keys_src.GeneratePrivateKeyResult.html) object containing the generated Wrapped Key ID, the PKP Ethereum address the Wrapped Key is associated with, and the public key of the generated private key +8. The SDK returns a [GeneratePrivateKeyResult](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/wrapped_keys_src.GeneratePrivateKeyResult.html) object containing the generated Wrapped Key ID, the PKP Ethereum address the Wrapped Key is associated with, and the public key of the generated private key ## Prerequisites @@ -83,11 +83,11 @@ When a Wrapped Key is generated, it's encrypted with the following [Access Contr where `pkpAddress` is the addressed derived from the `pkpSessionSigs`. This restricts the decryption of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which generated the Wrapped Key. -A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. +A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. #### `litNodeClient` -This is an instance of the [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. +This is an instance of the [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. #### `network` @@ -194,10 +194,10 @@ Here we are instantiating an instance of `LitNodeClient` and connecting it to th ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -219,8 +219,8 @@ The Auth Method used in this example implementation is signing a Sign in With Et ```ts import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -237,7 +237,7 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes diff --git a/docs/user-wallets/wrapped-keys/getting-wrapped-key-metadata.md b/docs/user-wallets/wrapped-keys/getting-wrapped-key-metadata.md index 8f3929e9..d49ee4a7 100644 --- a/docs/user-wallets/wrapped-keys/getting-wrapped-key-metadata.md +++ b/docs/user-wallets/wrapped-keys/getting-wrapped-key-metadata.md @@ -12,7 +12,7 @@ Below we will walk through an implementation of `getEncryptedKey`. The full code ## Overview of How it Works 1. The Wrapped Keys SDK will use the provided Wrapped Key ID and PKP Session Signatures to fetch the stored metadata for a specific Wrapped Key from the Wrapped Keys backend service -2. The stored metadata is returned as a [StoredKeyData](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/wrapped_keys_src.StoredKeyData.html) object +2. The stored metadata is returned as a [StoredKeyData](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/wrapped_keys_src.StoredKeyData.html) object ## Prerequisites @@ -73,11 +73,11 @@ When a Wrapped Key is generated, it's encrypted with the following [Access Contr where `pkpAddress` is the addressed derived from the `pkpSessionSigs`. This restricts the decryption of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which generated the Wrapped Key. -A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. +A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. #### `litNodeClient` -This is an instance of the [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. +This is an instance of the [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. #### `id` @@ -190,10 +190,10 @@ Here we are instantiating an instance of `LitNodeClient` and connecting it to th ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -215,8 +215,8 @@ The Auth Method used in this example implementation is signing a Sign in With Et ```ts import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -233,7 +233,7 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes diff --git a/docs/user-wallets/wrapped-keys/importing-key.md b/docs/user-wallets/wrapped-keys/importing-key.md index a2991982..e9d1fccb 100644 --- a/docs/user-wallets/wrapped-keys/importing-key.md +++ b/docs/user-wallets/wrapped-keys/importing-key.md @@ -16,10 +16,10 @@ Below we will walk through an implementation of `importPrivateKey`. The full cod 1. The Wrapped Keys SDK will derive the PKP's Ethereum address from the provided PKP Session Signatures 2. The SDK then generates the encryption Access Control Conditions using the derived Ethereum address - See the [Encrypting the Private Key](#encrypting-the-private-key) section for more info on this process -3. Using the generated Access Control Conditions, the SDK will encrypt the provided private key using the [encryptString](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) Lit SDK method +3. Using the generated Access Control Conditions, the SDK will encrypt the provided private key using the [encryptString](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) Lit SDK method - This encrypts your provided plaintext private key using the Lit network's public BLS key 4. The SDK then stores the private key encryption metadata to the Wrapped Keys backend service, associating it with the PKP's Ethereum address -5. The SDK returns a [ImportPrivateKeyResult](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/wrapped_keys_src.ImportPrivateKeyResult.html) object containing the generated Wrapped Key ID, and the PKP Ethereum address the Wrapped Key is associated with +5. The SDK returns a [ImportPrivateKeyResult](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/wrapped_keys_src.ImportPrivateKeyResult.html) object containing the generated Wrapped Key ID, and the PKP Ethereum address the Wrapped Key is associated with ## Prerequisites @@ -74,15 +74,15 @@ When a Wrapped Key is generated, it's encrypted with the following [Access Contr where `pkpAddress` is the address derived from the `pkpSessionSigs`. This restricts the decryption (and by extension, usage) of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which generated the Wrapped Key. -A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. +A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. #### `litNodeClient` -This is an instance of the [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. It's used to communicate with both the Lit network and the Wrapped Keys service. +This is an instance of the [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. It's used to communicate with both the Lit network and the Wrapped Keys service. #### `privateKey` -This parameter is the private key (as a clear text `string`) you're importing into the Lit network to be made into a Wrapped Key. The Wrapped Keys SDK encrypts it using the [encryptString](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method from the Lit SDK, with the following [Access Control Conditions](../../sdk/access-control/evm/basic-examples): +This parameter is the private key (as a clear text `string`) you're importing into the Lit network to be made into a Wrapped Key. The Wrapped Keys SDK encrypts it using the [encryptString](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method from the Lit SDK, with the following [Access Control Conditions](../../sdk/access-control/evm/basic-examples): ```ts [ @@ -204,10 +204,10 @@ Here we are instantiating an instance of `LitNodeClient` and connecting it to th ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -229,8 +229,8 @@ The Auth Method used in this example implementation is signing a Sign in With Et ```ts import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -247,7 +247,7 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes diff --git a/docs/user-wallets/wrapped-keys/listing-wrapped-keys.md b/docs/user-wallets/wrapped-keys/listing-wrapped-keys.md index 8599240e..fa68d618 100644 --- a/docs/user-wallets/wrapped-keys/listing-wrapped-keys.md +++ b/docs/user-wallets/wrapped-keys/listing-wrapped-keys.md @@ -70,11 +70,11 @@ When a Wrapped Key is generated, it's encrypted with the following [Access Contr where `pkpAddress` is the addressed derived from the `pkpSessionSigs`. This restricts the decryption of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which generated the Wrapped Key. -A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. +A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. #### `litNodeClient` -This is an instance of the [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. +This is an instance of the [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. ### Return Value @@ -171,10 +171,10 @@ Here we are instantiating an instance of `LitNodeClient` and connecting it to th ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -196,8 +196,8 @@ The Auth Method used in this example implementation is signing a Sign in With Et ```ts import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -214,7 +214,7 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes diff --git a/docs/user-wallets/wrapped-keys/sign-message.md b/docs/user-wallets/wrapped-keys/sign-message.md index 8071e784..bc6588c6 100644 --- a/docs/user-wallets/wrapped-keys/sign-message.md +++ b/docs/user-wallets/wrapped-keys/sign-message.md @@ -18,7 +18,7 @@ Below we will walk through an implementation of `signMessageWithEncryptedKey`. T - If `network` is `solana`, then the [signMessageWithSolanaEncryptedKey](https://github.com/LIT-Protocol/js-sdk/blob/master/packages/wrapped-keys/src/lib/litActions/solana/src/signMessageWithSolanaEncryptedKey.js) Lit Action is executed 3. The Lit Action will check the Access Control Conditions the plaintext private key was encrypted with to verify the PKP is authorized to decrypt the private key 4. If authorized, the Wrapped Key will be decrypted within a Lit node's TEE. If not authorized, an error will be returned -5. The Lit Action will use the decrypted Wrapped Key and the provided [SignMessageWithEncryptedKeyParams](https://v6-api-doc-lit-js-sdk.vercel.app/types/wrapped_keys_src.SignMessageWithEncryptedKeyParams.html) to sign the arbitrary message, returning the signed message +5. The Lit Action will use the decrypted Wrapped Key and the provided [SignMessageWithEncryptedKeyParams](https://v7-api-doc-lit-js-sdk.vercel.app/types/wrapped_keys_src.SignMessageWithEncryptedKeyParams.html) to sign the arbitrary message, returning the signed message ## Prerequisites @@ -72,11 +72,11 @@ When a Wrapped Key is generated, it's encrypted with the following [Access Contr where `pkpAddress` is the addressed derived from the `pkpSessionSigs`. This restricts the decryption of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which generated the Wrapped Key. -A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. +A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. #### `litNodeClient` -This is an instance of the [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. +This is an instance of the [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. #### `network` @@ -168,10 +168,10 @@ Here we are instantiating an instance of `LitNodeClient` and connecting it to th ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -193,8 +193,8 @@ The Auth Method used in this example implementation is signing a Sign in With Et ```ts import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -211,7 +211,7 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes diff --git a/docs/user-wallets/wrapped-keys/sign-transaction.md b/docs/user-wallets/wrapped-keys/sign-transaction.md index a70392ed..4ac28a4f 100644 --- a/docs/user-wallets/wrapped-keys/sign-transaction.md +++ b/docs/user-wallets/wrapped-keys/sign-transaction.md @@ -19,7 +19,7 @@ Below we will walk through an implementation of `signTransactionWithEncryptedKey 3. The Lit Action will verify the required transaction parameters were provided in order to sign the transaction 4. The Lit Action will check the Access Control Conditions the plaintext private key was encrypted with to verify the PKP is authorized to decrypt the private key 5. If authorized, the Wrapped Key will be decrypted within a Lit node's TEE. If not authorized, an error will be returned -6. The Lit Action will use the decrypted Wrapped Key and the provided [SignTransactionWithEncryptedKeyParams](https://v6-api-doc-lit-js-sdk.vercel.app/types/wrapped_keys_src.SignTransactionWithEncryptedKeyParams.html) to sign the transaction +6. The Lit Action will use the decrypted Wrapped Key and the provided [SignTransactionWithEncryptedKeyParams](https://v7-api-doc-lit-js-sdk.vercel.app/types/wrapped_keys_src.SignTransactionWithEncryptedKeyParams.html) to sign the transaction 7. If the `broadcast` parameter was set to `true`, the Lit Action will then broadcast the signed transaction to the specified `network`, returning the transaction hash. Otherwise, the signed transaction will be returned ## Prerequisites @@ -157,11 +157,11 @@ When a Wrapped Key is generated, it's encrypted with the following [Access Contr where `pkpAddress` is the addressed derived from the `pkpSessionSigs`. This restricts the decryption of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which generated the Wrapped Key. -A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. +A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. #### `litNodeClient` -This is an instance of the [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. +This is an instance of the [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. #### `network` @@ -483,10 +483,10 @@ Here we are instantiating an instance of `LitNodeClient` and connecting it to th ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -508,8 +508,8 @@ The Auth Method used in this example implementation is signing a Sign in With Et ```ts import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -526,7 +526,7 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes diff --git a/docs/user-wallets/wrapped-keys/storing-wrapped-key-metadata.md b/docs/user-wallets/wrapped-keys/storing-wrapped-key-metadata.md index 5ba075ba..7163efe0 100644 --- a/docs/user-wallets/wrapped-keys/storing-wrapped-key-metadata.md +++ b/docs/user-wallets/wrapped-keys/storing-wrapped-key-metadata.md @@ -14,12 +14,12 @@ Below we will walk through an implementation of `storeEncryptedKey`. The full co ## Overview of How it Works :::note -The [StoreEncryptedKeyParams](https://v6-api-doc-lit-js-sdk.vercel.app/types/wrapped_keys_src.StoreEncryptedKeyParams.html) required for this method include the encryption metadata of the private key that will be turned into a Wrapped Key. For more information on how to obtain the encryption metadata, please refer to this guide on [encrypting data using the Lit SDK](../../user-wallets/wrapped-keys/custom-wrapped-keys#generating-and-encrypting-a-private-key), and this guide on [Custom Wrapped Keys](../../user-wallets/wrapped-keys/custom-wrapped-keys#generating-and-encrypting-a-private-key). +The [StoreEncryptedKeyParams](https://v7-api-doc-lit-js-sdk.vercel.app/types/wrapped_keys_src.StoreEncryptedKeyParams.html) required for this method include the encryption metadata of the private key that will be turned into a Wrapped Key. For more information on how to obtain the encryption metadata, please refer to this guide on [encrypting data using the Lit SDK](../../user-wallets/wrapped-keys/custom-wrapped-keys#generating-and-encrypting-a-private-key), and this guide on [Custom Wrapped Keys](../../user-wallets/wrapped-keys/custom-wrapped-keys#generating-and-encrypting-a-private-key). ::: 1. The Wrapped Keys SDK will derive the PKP's Ethereum address from the provided PKP Session Signatures -2. The SDK stores the provided [StoreEncryptedKeyParams](https://v6-api-doc-lit-js-sdk.vercel.app/types/wrapped_keys_src.StoreEncryptedKeyParams.html) using the Wrapped Keys backend service, associating the resulting Wrapped Key with the PKP's Ethereum address -3. The SDK returns a [StoreEncryptedKeyResult](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/wrapped_keys_src.StoreEncryptedKeyResult.html) object containing the generated Wrapped Key ID, and the PKP Ethereum address the Wrapped Key is associated with +2. The SDK stores the provided [StoreEncryptedKeyParams](https://v7-api-doc-lit-js-sdk.vercel.app/types/wrapped_keys_src.StoreEncryptedKeyParams.html) using the Wrapped Keys backend service, associating the resulting Wrapped Key with the PKP's Ethereum address +3. The SDK returns a [StoreEncryptedKeyResult](https://v7-api-doc-lit-js-sdk.vercel.app/interfaces/wrapped_keys_src.StoreEncryptedKeyResult.html) object containing the generated Wrapped Key ID, and the PKP Ethereum address the Wrapped Key is associated with ## Prerequisites @@ -76,17 +76,17 @@ When a Wrapped Key is generated, it's encrypted with the following [Access Contr where `pkpAddress` is the addressed derived from the `pkpSessionSigs`. This restricts the decryption of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which generated the Wrapped Key. -A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. +A valid `pkpSessionSigs` object can be obtained using the [getPkpSessionSigs](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClientNodeJs.html#getPkpSessionSigs) helper method available on an instance of [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html). We dive deeper into obtaining a `pkpSessionSigs` using `getPkpSessionSigs` in the [Generating PKP Session Signatures](#generating-pkp-session-signatures) section of this guide. #### `litNodeClient` -This is an instance of the [LitNodeClient](https://v6-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. +This is an instance of the [LitNodeClient](https://v7-api-doc-lit-js-sdk.vercel.app/classes/lit_node_client_src.LitNodeClient.html) that is connected to a Lit network. #### `ciphertext` This is the result of encrypting the clear text private key and the Access Control Conditions for decryption using the Lit SDK. -This value can be obtained using the Lit SDK's [encryptString](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method: +This value can be obtained using the Lit SDK's [encryptString](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method: :::note In the below example, `process.env.PKP_ETH_ADDRESS` would be the Ethereum address of the PKP you would like to associate the Wrapped Key with. This restricts the decryption (and by extension, usage) of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which corresponds to this address. @@ -94,11 +94,11 @@ In the below example, `process.env.PKP_ETH_ADDRESS` would be the Ethereum addres ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; -import { encryptString } from '@lit-protocol/lit-node-client'; +import { LIT_NETWORK } from "@lit-protocol/constants"; +import { encryptString } from '@lit-protocol/encryption'; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -129,7 +129,7 @@ const { ciphertext, dataToEncryptHash } = await encryptString( This is the SHA-256 hash of the clear text private key. -This value can be obtained using the Lit SDK's [encryptString](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method: +This value can be obtained using the Lit SDK's [encryptString](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method: :::note In the below example, `process.env.PKP_ETH_ADDRESS` would be the Ethereum address of the PKP you would like to associate the Wrapped Key with. This restricts the decryption (and by extension, usage) of the Wrapped Key to only those whom can generate valid Authentication Signatures from the PKP which corresponds to this address. @@ -137,11 +137,11 @@ In the below example, `process.env.PKP_ETH_ADDRESS` would be the Ethereum addres ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; -import { encryptString } from '@lit-protocol/lit-node-client'; +import { LIT_NETWORK } from "@lit-protocol/constants"; +import { encryptString } from '@lit-protocol/encryption'; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -270,10 +270,10 @@ Here we are instantiating an instance of `LitNodeClient` and connecting it to th ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; +import { LIT_NETWORK } from "@lit-protocol/constants"; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); @@ -295,8 +295,8 @@ The Auth Method used in this example implementation is signing a Sign in With Et ```ts import { EthWalletProvider } from "@lit-protocol/lit-auth-client"; +import { LIT_ABILITY } from "@lit-protocol/constants"; import { - LitAbility, LitActionResource, LitPKPResource, } from "@lit-protocol/auth-helpers"; @@ -313,7 +313,7 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ resourceAbilityRequests: [ { resource: new LitActionResource("*"), - ability: LitAbility.LitActionExecution, + ability: LIT_ABILITY.LitActionExecution, }, ], expiration: new Date(Date.now() + 1000 * 60 * 10).toISOString(), // 10 minutes @@ -322,18 +322,18 @@ const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({ ### Encrypting the Private Key -In order to initialize a Wrapped Key, we need to store the encrypted underlying private key. This is done using the Lit SDK's [encryptString](https://v6-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method. +In order to initialize a Wrapped Key, we need to store the encrypted underlying private key. This is done using the Lit SDK's [encryptString](https://v7-api-doc-lit-js-sdk.vercel.app/functions/encryption_src.encryptString.html) method. ```ts import { LitNodeClient } from "@lit-protocol/lit-node-client"; -import { LitNetwork } from "@lit-protocol/constants"; -import { encryptString } from '@lit-protocol/lit-node-client'; +import { LIT_NETWORK } from "@lit-protocol/constants"; +import { encryptString } from '@lit-protocol/encryption'; import { api } from "@lit-protocol/wrapped-keys"; const { storeEncryptedKey } = api; const litNodeClient = new LitNodeClient({ - litNetwork: LitNetwork.DatilDev, + litNetwork: LIT_NETWORK.DatilDev, debug: false, }); await litNodeClient.connect(); diff --git a/docusaurus.config.js b/docusaurus.config.js index 86d14c54..ad375abd 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -154,7 +154,7 @@ const config = { }, { label: 'API', - href: 'https://v6-api-doc-lit-js-sdk.vercel.app/', + href: 'https://v7-api-doc-lit-js-sdk.vercel.app/', }, ], }, diff --git a/sidebars.js b/sidebars.js index 15891d5a..3582183c 100644 --- a/sidebars.js +++ b/sidebars.js @@ -88,6 +88,7 @@ const sidebars = { keywords: ['migrations'], }, items: [ + 'sdk/migrations/7.0.0', 'sdk/migrations/6.0.0', 'sdk/migrations/4.0.0', 'sdk/migrations/3.2.0', @@ -202,7 +203,6 @@ const sidebars = { 'sdk/authentication/session-sigs/siws-pkp-session-sigs', ], }, - 'sdk/authentication/session-sigs/usage', ], }, 'sdk/authentication/authenticating-siws', @@ -556,6 +556,7 @@ const sidebars = { keywords: ['api-reference'], }, items: [ + 'api-reference/v6-sdk', 'api-reference/v3-sdk', 'api-reference/v2-sdk', 'api-reference/v1-sdk', diff --git a/src/components/CardSectionsV3/LearnCode.jsx b/src/components/CardSectionsV3/LearnCode.jsx index 86ac696b..0918011f 100644 --- a/src/components/CardSectionsV3/LearnCode.jsx +++ b/src/components/CardSectionsV3/LearnCode.jsx @@ -15,7 +15,7 @@ export default function LearnCodeSection({ title, className }) {