You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solana-openai/nodejs/README.md
+22-21Lines changed: 22 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,18 @@
1
1
# Solana + OpenAI Example within a Lit Action
2
2
3
-
This code example demonstrates how an OpenAI API key can be used to generate a response to be signed by a Lit Solana Wrapped Key, all within the confines of Lit's Trusted Execution Environment (TEE).
3
+
This code example demonstrates how an OpenAI API key can be used to generate a response, which is then signed by a Lit Solana Wrapped Key—all within the confines of Lit's Trusted Execution Environment (TEE).
4
4
5
5
## Prerequisites
6
6
7
-
- An Ethereum private key
7
+
-**An Ethereum private key**
8
8
- This private key will be used to:
9
9
- Own the PKP we mint. The minted PKP will be used to create new Wrapped Keys.
10
10
- In order to pay for this, the corresponding Ethereum account must have Lit Test Tokens. If you do not have any, you can get some from [the faucet](https://chronicle-yellowstone-faucet.getlit.dev/)
11
-
- An OpenAI API key. We will use this to make a quest to OpenAI with our query to generate a response.
12
-
- This example currently used the GPT-4o-mini model, please enable this model on your API key or change it if needed.
13
-
- This code example uses Node.js and Yarn. Please have these installed before running the example
11
+
-**An OpenAI API key**
12
+
- We will use this to make a request to OpenAI with our query to generate a response.
13
+
- This example currently uses the GPT-4o-mini model, please enable this model on your API key or change it in the code if needed
14
+
-**Node.js and Yarn**
15
+
- Please have these installed before running the example
14
16
15
17
## Installation and Setup
16
18
@@ -32,31 +34,30 @@ Here's an overview of how the code example works:
32
34
1. Using an imported Ethereum private key, connect the wallet to the Lit RPC endpoint `Chronicle Yellowstone`
33
35
2. Connect to the Lit network using the `LitNodeClient` on the `datil-dev` network
34
36
3. Connect the `LitContracts` client to the Lit network (`datil-dev` in this case)
35
-
4.**If not provided in the .env file**: Mint a PKP
36
-
5.Create an AuthMethod using our Ethereum wallet
37
-
6. Use the created AuthMethod to be the authentication in generating Session Signatures for our PKP
38
-
7.Create a new Solana Wrapped Key
39
-
8.Fetch the encrypted metadata of our Wrapped Key
40
-
9.Define Access Control Conditions to encrypt our OpenAI API key with. This will ensure it is not revealed at any point. The ACCs are the same ones used to encrypt the Wrapped Key metadata.
41
-
10. Write a simple prompt for our AI to answer
42
-
11.Execute the Lit Action, providing our encrypted Solana Wrapped Key and OpenAI API key metadata, as well as our prompt.
37
+
4.**If PKP idnot provided in the .env file**: Mint a new PKP.
38
+
5.Use your Ethereum wallet to create an AuthMethod.
39
+
6. Use the created AuthMethod for authentication in generating session signatures for our PKP.
40
+
7.Generate a new Solana Wrapped Key.
41
+
8.Retrieve the encrypted metadata of our Wrapped Key.
42
+
9.Set up Access Control Conditions (ACCs) to encrypt our OpenAI API key. This ensures it is not revealed at any point. The ACCs are the same ones used to encrypt the Wrapped Key metadata.
43
+
10. Write a simple prompt for the AI to answer.
44
+
11.Run the Lit Action, providing our encrypted Solana Wrapped Key and OpenAI API key metadata, as well as our prompt.
43
45
44
46
### Lit Action Overview
45
47
46
48
Within the Lit Action:
47
49
48
-
1. Decrypt the Solana Wrapped Key and OpenAI API key
49
-
2. Remove the salt from the decrypted Solana private key
50
-
3.Query OpenAI for a response to the prompt
51
-
4.Create a Solana keypair from the decrypted private key
52
-
5. Use the Solana keypair to sign the OpenAI response
53
-
6.Verify the signature
50
+
1. Decrypt the Solana Wrapped Key and OpenAI API key.
51
+
2. Remove the salt from the decrypted Solana private key.
52
+
3.Send the prompt to OpenAI and receive a response.
53
+
4.Generate a Solana keypair from the decrypted private key.
54
+
5. Use the Solana keypair to sign the OpenAI response.
55
+
6.Ensure the signature is valid.
54
56
55
57
### Expected Output
56
58
57
59
After running the test, the end of the output in the console should appear similar to:
58
60
59
-
60
61
```ts
61
62
✅ ExecutedtheLitAction
62
63
{
@@ -79,7 +80,7 @@ After running the test, the end of the output in the console should appear simil
79
80
80
81
## Specific Files to Reference
81
82
82
-
-[./src/index.ts](./src/index.ts): Contains the logic for the example
83
+
-[./src/index.ts](./src/index.ts): Contains the core logic for the example
83
84
-[./src/litAction.js](./src/litAction.js): Contains the Lit Action code that will be bundled
84
85
-[./src/litAction.bundle.js](./src/litAction.bundle.js): Contains the bundled Lit Action code
85
86
-[./src/utils.ts](./src/utils.ts): Contains the code for minting a new PKP and ensuring the required environment variables are set
0 commit comments