From 40d467bf55412267cda5d663219c8c151579b32a Mon Sep 17 00:00:00 2001 From: Brieyla Date: Fri, 17 Nov 2023 17:21:03 +0400 Subject: [PATCH 1/2] fixed typo about lit initialization --- .../SDKExamples/OnchainMetadata/setup.md | 12 ++++++++---- .../version-2.0/sdk/explanation/encryption.md | 12 ++++++------ .../version-2.0/sdk/explanation/installation.md | 14 ++++++++------ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/versioned_docs/version-2.0/ToolsAndExamples/SDKExamples/OnchainMetadata/setup.md b/versioned_docs/version-2.0/ToolsAndExamples/SDKExamples/OnchainMetadata/setup.md index 2845323b..99232974 100644 --- a/versioned_docs/version-2.0/ToolsAndExamples/SDKExamples/OnchainMetadata/setup.md +++ b/versioned_docs/version-2.0/ToolsAndExamples/SDKExamples/OnchainMetadata/setup.md @@ -1,27 +1,30 @@ --- sidebar_position: 2 --- - # Setup the Project ## Smart Contract 1. Install hardhat: + ```js yarn add hardhat ``` 2. Init hardhat to create the boilerplate for a **Basic project (with Javascript)**: + ```js npx hardhat init ``` 3. Install Openzepplin: + ```js yarn add @openzeppelin/contracts ``` 4. Test deploy the sample smart contract on 2 separate terminals: + ```js npx hardhat node npx hardhat run scripts/deploy.js --network localhost @@ -33,17 +36,18 @@ Now that we have our hardhat working & the sample smart contract is deployed cor You can use the Lit JS SDK V2 to encrypt and store any static content. This could be a file, a string, or anything that won't change (we're going to encrypt an input string). You have to store the content and metadata yourself (we're storing that on a blockchain network), but Lit will store who is allowed to decrypt it and enforce this (aka key management). - 1. Install Lit JS SDK V2: + ```js yarn add @lit-protocol/lit-node-client ``` 2. Create a Lit class which will have all the encryption & decryption functions we require: + ```js import * as LitJsSdk from "@lit-protocol/lit-node-client"; -const client = new LitJsSdk.LitNodeClient(); +const client = new LitJsSdk.LitNodeClient({}); class Lit { litNodeClient; @@ -60,4 +64,4 @@ class Lit { `client.connect()` will return a promise that resolves when you are connected to the Lit Network. You may also listen for the `lit-ready` event. In this code example, the `litNodeClient` is set as a global variable for use throughout the web app. -::: \ No newline at end of file +::: diff --git a/versioned_docs/version-2.0/sdk/explanation/encryption.md b/versioned_docs/version-2.0/sdk/explanation/encryption.md index 77dbf0a3..e6abdb43 100644 --- a/versioned_docs/version-2.0/sdk/explanation/encryption.md +++ b/versioned_docs/version-2.0/sdk/explanation/encryption.md @@ -1,8 +1,8 @@ --- sidebar_position: 3 --- - # Encryption + You can use Lit to encrypt and store any static content. This could be a file, a string, or anything that won't change. You need to store the content and metadata yourself (on IPFS, Arweave, or even a centralized storage solution), and Lit will store who is allowed to decrypt it and enforce this (aka key management). If you want to use IPFS as a storage solution, Lit has an `encryptToIpfs` function that will help streamline the process of encryption and storing the encrypted data. You will need to provide an Infura ID and API secret key. [Jump to encryptToIPFS](../../SDK/Explanation/encryption#encrypttoipfs). @@ -18,8 +18,9 @@ This example will show you how to encrypt and decrypt static data using the Lit At the top of your file, instantiate your Lit Node client like so: ```js -const client = new LitJsSdk.LitNodeClient(); -const chain = "ethereum"; +import * as LitJsSdk from "@lit-protocol/lit-node-client"; + +const client = new LitJsSdk.LitNodeClient({}); ``` Create a Lit class and set the litNodeClient. @@ -42,12 +43,12 @@ export default new Lit() Get more info on functions in the [API docs](https://js-sdk.litprotocol.com/index.html). Steps to Encrypt + 1. Obtain an `authSig` and create an access control condition. 2. Encrypt the static content (string, file, etc.) to get the `encryptedString`, for example. 3. Use `litNodeClient.saveEncryptionKey` to tie the `accessControlConditions` with the `symmetricKey` we got above. This returns us the `encryptedSymmetricKey`. 4. Finally, we have to store the `encryptedString` & other metadata: `encryptedSymmetricKey`, `accessControlConditions` (or other conditions eg: `evmContractConditions`) and `chain`. IPFS is generally used to store these values. - ### Access Control & AuthSig In this example, we will set the accessControlConditions on if a wallet has at least 0.000001 ETH: @@ -207,7 +208,6 @@ The full decryption process should look like: } ``` - # Encryption & Upload to IPFS To simplify encrypting and uploading to IPFS, there is a method within the SDK to help encrypt and store data on IPFS. @@ -261,4 +261,4 @@ async decrypt(ipfsCid) { ### How to encrypt & decrypt a file instead? -For encryption use the same function params as above with the string param replaced with a file. For decryption nothing changes. The returned value in that case will be a Uint8Array instead of a string since it's a decrypted file. \ No newline at end of file +For encryption use the same function params as above with the string param replaced with a file. For decryption nothing changes. The returned value in that case will be a Uint8Array instead of a string since it's a decrypted file. diff --git a/versioned_docs/version-2.0/sdk/explanation/installation.md b/versioned_docs/version-2.0/sdk/explanation/installation.md index 7dcc6de8..d8d31be5 100644 --- a/versioned_docs/version-2.0/sdk/explanation/installation.md +++ b/versioned_docs/version-2.0/sdk/explanation/installation.md @@ -1,7 +1,6 @@ --- sidebar_position: 1 --- - import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; @@ -22,7 +21,7 @@ values={[ {label: 'script tag with all dependencies included', value: 'script-tag'}, {label: 'server side with nodejs', value: 'server-side'}, ]}> - +`` Install the `@lit-protocol/lit-node-client` package, which can be used in both browser and Node environments: @@ -37,7 +36,7 @@ import * as LitJsSdk from "@lit-protocol/lit-node-client"; ``` - + ```js @@ -45,7 +44,7 @@ import * as LitJsSdk from "@lit-protocol/lit-node-client"; ``` If you decide to import the SDK with the script tag, we provide a web-ready package with the dependencies you need. You can use the SDK functions via `LitJsSdk_litNodeClient`, for example `LitJsSdk_litNodeClient.encryptString()` - +`` @@ -80,10 +79,13 @@ values={[ {label: 'yarn / NPM', value: 'yarn'}, {label: 'script tag', value: 'script'}, ]}> - +`` ```js -const client = new LitJsSdk.LitNodeClient(); +import * as LitJsSdk from "@lit-protocol/lit-node-client"; + + +const client = new LitJsSdk.LitNodeClient({}); await client.connect(); window.litNodeClient = client; ``` From ce81480fdac18f3761ea9d1717403ce83f6f97ff Mon Sep 17 00:00:00 2001 From: Brieyla Date: Fri, 17 Nov 2023 17:28:23 +0400 Subject: [PATCH 2/2] small refactoring --- .../SDKExamples/OnchainMetadata/setup.md | 10 +++------- .../version-2.0/sdk/explanation/encryption.md | 8 +++++--- .../version-2.0/sdk/explanation/installation.md | 12 +++++------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/versioned_docs/version-2.0/ToolsAndExamples/SDKExamples/OnchainMetadata/setup.md b/versioned_docs/version-2.0/ToolsAndExamples/SDKExamples/OnchainMetadata/setup.md index 99232974..c0cf357d 100644 --- a/versioned_docs/version-2.0/ToolsAndExamples/SDKExamples/OnchainMetadata/setup.md +++ b/versioned_docs/version-2.0/ToolsAndExamples/SDKExamples/OnchainMetadata/setup.md @@ -1,30 +1,27 @@ --- sidebar_position: 2 --- + # Setup the Project ## Smart Contract 1. Install hardhat: - ```js yarn add hardhat ``` 2. Init hardhat to create the boilerplate for a **Basic project (with Javascript)**: - ```js npx hardhat init ``` 3. Install Openzepplin: - ```js yarn add @openzeppelin/contracts ``` 4. Test deploy the sample smart contract on 2 separate terminals: - ```js npx hardhat node npx hardhat run scripts/deploy.js --network localhost @@ -36,14 +33,13 @@ Now that we have our hardhat working & the sample smart contract is deployed cor You can use the Lit JS SDK V2 to encrypt and store any static content. This could be a file, a string, or anything that won't change (we're going to encrypt an input string). You have to store the content and metadata yourself (we're storing that on a blockchain network), but Lit will store who is allowed to decrypt it and enforce this (aka key management). -1. Install Lit JS SDK V2: +1. Install Lit JS SDK V2: ```js yarn add @lit-protocol/lit-node-client ``` 2. Create a Lit class which will have all the encryption & decryption functions we require: - ```js import * as LitJsSdk from "@lit-protocol/lit-node-client"; @@ -64,4 +60,4 @@ class Lit { `client.connect()` will return a promise that resolves when you are connected to the Lit Network. You may also listen for the `lit-ready` event. In this code example, the `litNodeClient` is set as a global variable for use throughout the web app. -::: +::: \ No newline at end of file diff --git a/versioned_docs/version-2.0/sdk/explanation/encryption.md b/versioned_docs/version-2.0/sdk/explanation/encryption.md index e6abdb43..44039950 100644 --- a/versioned_docs/version-2.0/sdk/explanation/encryption.md +++ b/versioned_docs/version-2.0/sdk/explanation/encryption.md @@ -1,8 +1,8 @@ --- sidebar_position: 3 --- -# Encryption +# Encryption You can use Lit to encrypt and store any static content. This could be a file, a string, or anything that won't change. You need to store the content and metadata yourself (on IPFS, Arweave, or even a centralized storage solution), and Lit will store who is allowed to decrypt it and enforce this (aka key management). If you want to use IPFS as a storage solution, Lit has an `encryptToIpfs` function that will help streamline the process of encryption and storing the encrypted data. You will need to provide an Infura ID and API secret key. [Jump to encryptToIPFS](../../SDK/Explanation/encryption#encrypttoipfs). @@ -17,6 +17,7 @@ This example will show you how to encrypt and decrypt static data using the Lit At the top of your file, instantiate your Lit Node client like so: + ```js import * as LitJsSdk from "@lit-protocol/lit-node-client"; @@ -43,12 +44,12 @@ export default new Lit() Get more info on functions in the [API docs](https://js-sdk.litprotocol.com/index.html). Steps to Encrypt - 1. Obtain an `authSig` and create an access control condition. 2. Encrypt the static content (string, file, etc.) to get the `encryptedString`, for example. 3. Use `litNodeClient.saveEncryptionKey` to tie the `accessControlConditions` with the `symmetricKey` we got above. This returns us the `encryptedSymmetricKey`. 4. Finally, we have to store the `encryptedString` & other metadata: `encryptedSymmetricKey`, `accessControlConditions` (or other conditions eg: `evmContractConditions`) and `chain`. IPFS is generally used to store these values. + ### Access Control & AuthSig In this example, we will set the accessControlConditions on if a wallet has at least 0.000001 ETH: @@ -208,6 +209,7 @@ The full decryption process should look like: } ``` + # Encryption & Upload to IPFS To simplify encrypting and uploading to IPFS, there is a method within the SDK to help encrypt and store data on IPFS. @@ -261,4 +263,4 @@ async decrypt(ipfsCid) { ### How to encrypt & decrypt a file instead? -For encryption use the same function params as above with the string param replaced with a file. For decryption nothing changes. The returned value in that case will be a Uint8Array instead of a string since it's a decrypted file. +For encryption use the same function params as above with the string param replaced with a file. For decryption nothing changes. The returned value in that case will be a Uint8Array instead of a string since it's a decrypted file. \ No newline at end of file diff --git a/versioned_docs/version-2.0/sdk/explanation/installation.md b/versioned_docs/version-2.0/sdk/explanation/installation.md index d8d31be5..63fe11e7 100644 --- a/versioned_docs/version-2.0/sdk/explanation/installation.md +++ b/versioned_docs/version-2.0/sdk/explanation/installation.md @@ -1,6 +1,7 @@ --- sidebar_position: 1 --- + import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; @@ -21,7 +22,7 @@ values={[ {label: 'script tag with all dependencies included', value: 'script-tag'}, {label: 'server side with nodejs', value: 'server-side'}, ]}> -`` + Install the `@lit-protocol/lit-node-client` package, which can be used in both browser and Node environments: @@ -36,7 +37,7 @@ import * as LitJsSdk from "@lit-protocol/lit-node-client"; ``` - + ```js @@ -44,7 +45,7 @@ import * as LitJsSdk from "@lit-protocol/lit-node-client"; ``` If you decide to import the SDK with the script tag, we provide a web-ready package with the dependencies you need. You can use the SDK functions via `LitJsSdk_litNodeClient`, for example `LitJsSdk_litNodeClient.encryptString()` -`` + @@ -79,12 +80,9 @@ values={[ {label: 'yarn / NPM', value: 'yarn'}, {label: 'script tag', value: 'script'}, ]}> -`` + ```js -import * as LitJsSdk from "@lit-protocol/lit-node-client"; - - const client = new LitJsSdk.LitNodeClient({}); await client.connect(); window.litNodeClient = client;