Signup with sdk

This commit is contained in:
Gilbert
2024-04-23 21:21:58 -05:00
parent 748ca507da
commit c395be82b5
38 changed files with 3240 additions and 328 deletions
+37
View File
@@ -0,0 +1,37 @@
import { SiweMessage } from 'siwe';
import { PKPEthersWallet } from '@lit-protocol/pkp-ethers';
import { v4 as uuid } from 'uuid';
const domain = window.location.host;
const origin = window.location.origin;
export async function signInWithEthereum(wallet: PKPEthersWallet) {
const message = await createSiweMessage(
await wallet.getAddress(),
'Sign in with Ethereum to the app.',
);
const signature = await wallet.signMessage(message);
const res = await fetch(`${import.meta.env.VITE_SERVER_URL}/auth/validate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message, signature }),
credentials: 'include',
});
console.log(await res.text());
}
async function createSiweMessage(address: string, statement: string) {
const message = new SiweMessage({
domain,
address,
statement,
uri: origin,
version: '1',
chainId: 1,
nonce: uuid().replace(/[^a-z0-9]/g, ''),
});
return message.prepareMessage();
}
-19
View File
@@ -1,19 +0,0 @@
// import { LitGoogleAuth } from '@snowballtools/auth-lit';
// import { Snowball, SnowballChain } from '@snowballtools/js-sdk';
// // import { LinkLitAlchemyLight } from '@snowballtools/link-lit-alchemy-light';
// export const DOMAIN = import.meta.env.VITE_DOMAIN || 'localhost';
// export const ORIGIN =
// import.meta.env.VITE_VERCEL_ENV === 'production'
// ? `https://${DOMAIN}`
// : `http://${DOMAIN}:3000`;
// // prettier-ignore
// export const snowball = Snowball.withAuth(
// LitGoogleAuth.configure({
// litReplayApiKey: import.meta.env.VITE_LIT_RELAY_API_KEY!,
// }),
// ).create({
// initialChain: SnowballChain.sepolia,
// });
+22 -10
View File
@@ -1,13 +1,25 @@
// import { useEffect, useState } from 'react';
// import { snowball } from './snowball';
import { useEffect, useState } from 'react';
import { Snowball, SnowballChain } from '@snowballtools/js-sdk';
import { LitGoogleAuth, LitPasskeyAuth } from '@snowballtools/auth-lit';
// export function useSnowball() {
// const [state, setState] = useState(100);
export const snowball = Snowball.withAuth({
google: LitGoogleAuth.configure({
litRelayApiKey: import.meta.env.VITE_LIT_RELAY_API_KEY!,
}),
passkey: LitPasskeyAuth.configure({
litRelayApiKey: import.meta.env.VITE_LIT_RELAY_API_KEY!,
}),
}).create({
initialChain: SnowballChain.sepolia,
});
// useEffect(() => {
// // Subscribe and directly return the unsubscribe function
// return snowball.subscribe(() => setState(state + 1));
// }, [snowball]);
export function useSnowball() {
const [state, setState] = useState(100);
// return snowball;
// }
useEffect(() => {
// Subscribe and directly return the unsubscribe function
return snowball.subscribe(() => setState(state + 1));
}, [state]);
return snowball;
}