Skip to content

Commit 03f8c10

Browse files
committed
Merge branch 'master' into wyatt/wrapped-keys-eip-712
2 parents 768ec81 + a74e6f6 commit 03f8c10

File tree

126 files changed

+39645
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+39645
-564
lines changed

siws-accs/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-accs/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-accs/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-accs/browser/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Sign-in With Solana Access Control Conditions
2+
3+
The code example demonstrates how to create [Lit Access Control Conditions (ACCs)](https://developer.litprotocol.com/sdk/access-control/evm/basic-examples) that only allow access if a specific Solana wallet has signed a Sign-in With Solana (SIWS) message as defined by [Phantom's specification](https://github.com/phantom/sign-in-with-solana/tree/main?tab=readme-ov-file).
4+
5+
This code example has a [corresponding doc page](https://developer.litprotocol.com/sdk/access-control/solana/siws-access-control) that covers the implementation in more detail, this repository acts as a reference implementation for you to use as a guide for implementing SIWS ACCs in your project.
6+
7+
An example use case fo this functionality is permitting decryption capabilities to specific users on Solana based on their wallet address.
8+
9+
## Prerequisites
10+
11+
- An Ethereum private key
12+
- This private key will be used to:
13+
- Mint a Lit Capacity Credit if none was specific in the project's `.env` file
14+
- 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/)
15+
- Create a Lit Capacity Credit delegation Auth Sig
16+
- 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, Yarn, and Deno please have these installed before running the example
18+
- 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
19+
20+
## Installation and Setup
21+
22+
1. Clone the repository
23+
2. `cd` into the code example directory: `cd siws-accs/browser`
24+
3. Install the dependencies: `yarn`
25+
4. Create and fill in the `.env` file: `cp .env.example .env`
26+
- `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
27+
5. Build the Lit Action file: `yarn build:lit-action`
28+
6. Start the development server: `yarn dev`
29+
30+
## Executing the Example
31+
32+
1. Open the app in your browser: http://localhost:5173
33+
2. Open the JavaScript browser console
34+
3. Click the `Select Wallet` button and connect your Phantom wallet
35+
4. Click the `Sign In` button to sign the SIWS message
36+
37+
The following diagram provides an overview of how this code example works:
38+
39+
![Code Example Overview](./src/assets/siws-accs.png)
40+
41+
### Expected Output
42+
43+
After clicking the `Sign In` button, the code example will submit your signed SIWS message to the Lit network to be authenticated using Lit Action and ACCs that only returns true if the SIWS message was signed by your Solana public key.
44+
45+
After successful execution, you should see `✅ Successfully signed SIWS message` in the JavaScript console and `Authentication Successful` on the web page:
46+
47+
![Successful execution](./src/assets/successful-execution.png)
48+
49+
## Specific Files to Reference
50+
51+
- [App.tsx](./src/App.tsx): Contains the frontend code and logic for the example
52+
- [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
53+
- [litSiws.ts](./src/litSiws.ts): Contains the code for the generating the ACCs, generating Session Signatures, and executing the Lit Action
54+
- [litActionSiws.ts](./src/litActionSiws.ts): Contains the Lit Action code that authenticates the SIWS message, and executes the ACCs to check for authorization

siws-accs/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-accs/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.

siws-accs/browser/esbuild-shims.js

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-accs/browser/esbuild.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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: ["src/litActionSiws.ts"],
7+
outdir: "src/dist/",
8+
bundle: true,
9+
platform: "browser",
10+
format: "esm",
11+
target: "esnext",
12+
minify: false,
13+
inject: ["./esbuild-shims.js"],
14+
});
15+
await esbuild.stop();

siws-accs/browser/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
<style>
9+
body,
10+
html {
11+
margin: 0;
12+
height: 100%;
13+
display: flex;
14+
justify-content: center;
15+
align-items: center;
16+
}
17+
#root {
18+
width: 100%;
19+
text-align: center;
20+
}
21+
</style>
22+
</head>
23+
<body>
24+
<div id="root"></div>
25+
<script type="module" src="/src/main.tsx"></script>
26+
</body>
27+
</html>

siws-accs/browser/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "siws-accs-browser",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "tsc -b && vite build",
9+
"build:lit-action": "deno task bundle",
10+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
11+
"preview": "vite preview"
12+
},
13+
"dependencies": {
14+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
15+
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
16+
"@lit-protocol/auth-browser": "^6.7.0",
17+
"@lit-protocol/auth-helpers": "^6.5.3",
18+
"@lit-protocol/constants": "^6.5.3",
19+
"@lit-protocol/contracts-sdk": "^6.8.1",
20+
"@lit-protocol/lit-node-client": "^6.5.3",
21+
"@simplewebauthn/browser": "^10.0.0",
22+
"@solana/wallet-adapter-base": "^0.9.23",
23+
"@solana/wallet-adapter-react": "^0.15.35",
24+
"@solana/wallet-adapter-react-ui": "^0.9.35",
25+
"@solana/wallet-adapter-wallets": "^0.19.32",
26+
"@solana/wallet-standard-features": "^1.2.0",
27+
"@solana/wallet-standard-util": "^1.1.1",
28+
"@solana/web3.js": "^1.95.3",
29+
"@vitejs/plugin-react-swc": "^3.7.0",
30+
"ethers": "v5",
31+
"ipfs-only-hash": "^4.0.0",
32+
"react": "^18.3.1",
33+
"react-dom": "^18.3.1",
34+
"rollup-plugin-polyfill-node": "^0.13.0",
35+
"vite-plugin-node-polyfills": "^0.22.0"
36+
},
37+
"devDependencies": {
38+
"@lit-protocol/types": "^6.6.0",
39+
"@types/react": "^18.3.3",
40+
"@types/react-dom": "^18.3.0",
41+
"@typescript-eslint/eslint-plugin": "^7.13.1",
42+
"@typescript-eslint/parser": "^7.13.1",
43+
"@vitejs/plugin-react": "^4.3.1",
44+
"eslint": "^8.57.0",
45+
"eslint-plugin-react-hooks": "^4.6.2",
46+
"eslint-plugin-react-refresh": "^0.4.7",
47+
"typescript": "^5.5.3",
48+
"typestub-ipfs-only-hash": "^4.0.0",
49+
"vite": "^5.3.1"
50+
}
51+
}

0 commit comments

Comments
 (0)