forked from cerc-io/snowballtools-base
Signup with sdk
This commit is contained in:
@@ -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();
|
||||
}
|
||||
@@ -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,
|
||||
// });
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user