Skip to content

Commit a74e6f6

Browse files
Merge pull request #64 from LIT-Protocol/wyatt/siws
Inits SIWS example to generate Session Sigs and decrypt a string
2 parents f4f2312 + 145b959 commit a74e6f6

36 files changed

+9885
-3
lines changed

siws-accs/browser/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ An example use case fo this functionality is permitting decryption capabilities
1414
- 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/)
1515
- Create a Lit Capacity Credit delegation Auth Sig
1616
- Create Lit Session Signatures for the request to the Lit network to execute a Lit Action that authenticates the SIWS message and check for authorization by executing the Access Control Conditions
17-
- This code example uses Node.js and Yarn, please have these installed before running the example
17+
- This code example uses Node.js, Yarn, and Deno please have these installed before running the example
1818
- The code example also expects the [Phantom wallet browser extension](https://chromewebstore.google.com/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa?hl=en) to be installed and setup with a Solana wallet
1919

2020
## Installation and Setup

siws-authentication/browser/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This code example has a [corresponding doc page](https://developer.litprotocol.c
1111
- Mint a Lit Capacity Credit if none was specific in the project's `.env` file
1212
- 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/)
1313
- Create a Lit Capacity Credit delegation Auth Sig
14-
- This code example uses Node.js and Yarn, please have these installed before running the example
14+
- This code example uses Node.js, Yarn, and Deno please have these installed before running the example
1515
- The code example also expects the [Phantom wallet browser extension](https://chromewebstore.google.com/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa?hl=en) to be installed and setup with a Solana wallet
1616

1717
## Installation and Setup

siws-encryption/browser/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_ETHEREUM_PRIVATE_KEY=

siws-encryption/browser/.eslintrc.cjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
root: true,
3+
env: { browser: true, es2020: true },
4+
extends: [
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:react-hooks/recommended",
8+
],
9+
ignorePatterns: ["dist", ".eslintrc.cjs"],
10+
parser: "@typescript-eslint/parser",
11+
plugins: ["react-refresh"],
12+
rules: {
13+
"react-refresh/only-export-components": [
14+
"warn",
15+
{ allowConstantExport: true },
16+
],
17+
},
18+
};

siws-encryption/browser/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

siws-encryption/browser/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Encrypting Data with Sign-in With Solana
2+
3+
This example demonstrates how to use Lit Protocol to encrypt and decrypt data based on authenticated Solana public keys. It leverages three key components:
4+
5+
1. Lit Access Control Conditions
6+
2. Sign-in With Solana (SIWS) messages (following [Phantom's specification](https://github.com/phantom/sign-in-with-solana/tree/main))
7+
3. Lit Actions
8+
9+
By combining these technologies, we create a secure system for data decryption tied to Solana wallet authentication.
10+
11+
This code example has a [corresponding doc page](https://developer.litprotocol.com/sdk/access-control/solana/siws-encryption) that covers the implementation in more detail, this repository acts as a reference implementation for you to use as a guide for restricting data decryption to specific Solana public keys in your project.
12+
13+
## Prerequisites
14+
15+
- An Ethereum private key
16+
- This private key will be used to:
17+
- Mint a Lit Capacity Credit if none was specific in the project's `.env` file
18+
- 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/)
19+
- Create a Lit Capacity Credit delegation Auth Sig
20+
- Mint a PKP if none was specific in the project's `.env` file
21+
- This code example uses Node.js, Yarn, and Deno please have these installed before running the example
22+
- The code example also expects the [Phantom wallet browser extension](https://chromewebstore.google.com/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa?hl=en) to be installed and setup with a Solana wallet
23+
24+
## Installation and Setup
25+
26+
1. Clone the repository
27+
2. `cd` into the code example directory: `cd siws-session-sigs/browser`
28+
3. Install the dependencies: `yarn`
29+
4. Create and fill in the `.env` file: `cp .env.example .env`
30+
- `VITE_ETHEREUM_PRIVATE_KEY`: **Required** This is the Ethereum private key that will be used to mint a Lit Capacity Credit and create Lit Session Signatures
31+
- `VITE_LIT_CAPACITY_CREDIT_TOKEN_ID`: **Optional** This is the ID of the Lit Capacity Credit to use for the PKP delegation Auth Sig
32+
- `VITE_LIT_PKP_PUBLIC_KEY`: **Optional** This is the public key of the PKP to use for generating Session Signatures
33+
- `VITE_LIT_PKP_TOKEN_ID`: **Optional** This is the ID of the PKP to use for generating Session Signatures
34+
5. Build the Lit Action file: `yarn build:lit-action`
35+
6. Start the development server: `yarn dev`
36+
37+
## Executing the Example
38+
39+
1. Open the app in your browser: http://localhost:5173
40+
2. Open the JavaScript browser console
41+
3. Click the `Select Wallet` button and connect your Phantom wallet
42+
4. Click the `Sign In` button to sign the SIWS message
43+
5. Enter some text in the encryption input field and click the `Encrypt` button
44+
6. Click the `Decrypt` button to decrypt the data
45+
46+
The following diagram provides an overview of how this code example works:
47+
48+
![Code Example Overview](./src/assets/siws-session-signatures.png)
49+
50+
### Expected Output
51+
52+
After clicking the `Sign In` button, the code example will submit your signed SIWS message to the Lit network to be authenticated using a Lit Action and will generate Session Signatures using the minted PKP if the signing Solana public key is authorized to use the PKP.
53+
54+
After successful execution, you should see `✅ Got Session sigs` in the JavaScript console and `Session Sigs generated successfully` on the web page:
55+
56+
![Successful execution](./src/assets/successful-execution.png)
57+
58+
## Specific Files to Reference
59+
60+
- [App.tsx](./src/App.tsx): Contains the frontend code and logic for the example
61+
- [SignInButton.tsx](./src/SignInButton.tsx): Contains the code for the `Sign In` button that creates and submits the SIWS message to the browser wallet extension
62+
- [litSiws.ts](./src/litSiws.ts): Contains the code for:
63+
- Minting a Capacity Credit if none was specified in the `.env` file
64+
- Generating the Capacity Credit delegation Auth Sig
65+
- Minting a PKP if none was specified in the `.env` file
66+
- Adding the permitted Auth Methods to the PKP
67+
- Executing the Lit Action to authenticate the SIWS message and generate Session Signatures
68+
- [litActionSessionSigs.ts](./src/litActionSessionSigs.ts): Contains the Lit Action code that authenticates the SIWS message, checks the PKPs permitted Auth Methods, and signals the Lit Network to generate Session Signatures

siws-encryption/browser/deno.jsonc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tasks": {
3+
"bundle": "deno run --allow-read --allow-write --allow-env --allow-net --allow-run esbuild.js"
4+
}
5+
}

siws-encryption/browser/deno.lock

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
globalThis.process = {
2+
env: {},
3+
};

siws-encryption/browser/esbuild.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
2+
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.10.3";
3+
4+
esbuild.build({
5+
plugins: [...denoPlugins()],
6+
entryPoints: [
7+
"src/litActions/litActionSessionSigs.ts",
8+
"src/litActions/litActionDecrypt.ts",
9+
],
10+
outdir: "src/litActions/dist/",
11+
bundle: true,
12+
platform: "browser",
13+
format: "esm",
14+
target: "esnext",
15+
minify: false,
16+
inject: ["./esbuild-shims.js"],
17+
});
18+
await esbuild.stop();

0 commit comments

Comments
 (0)