Skip to content

Commit

Permalink
add domain, address, and statement to example SIWS
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaaash committed Aug 7, 2023
1 parent 81d156f commit aef5453
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/starter/example/src/components/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ const WalletContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
const autoSignIn = useCallback(async (adapter: Adapter) => {
if (!('signIn' in adapter)) return true;

const input: SolanaSignInInput = {};
const input: SolanaSignInInput = {
domain: window.location.host,
address: adapter.publicKey ? adapter.publicKey.toBase58() : undefined,
statement: 'Please sign in.',
};
const output = await adapter.signIn(input);

if (!verifySignIn(input, output)) throw new Error('Sign In verification failed!');
Expand Down
16 changes: 12 additions & 4 deletions packages/starter/example/src/components/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { Button } from '@mui/material';
import { useWallet } from '@solana/wallet-adapter-react';
import type { SolanaSignInInput } from '@solana/wallet-standard-features';
import { verifySignIn } from '@solana/wallet-standard-util';
import bs58 from 'bs58';
import type { FC } from 'react';
import React, { useCallback } from 'react';
import { useNotify } from './notify';

export const SignIn: FC = () => {
const { signIn } = useWallet();
const { signIn, publicKey } = useWallet();
const notify = useNotify();

const onClick = useCallback(async () => {
try {
if (!signIn) throw new Error('Wallet does not support message signing!');
if (!signIn) throw new Error('Wallet does not support Sign In With Solana!');

const { signature } = await signIn();
const input: SolanaSignInInput = {
domain: window.location.host,
address: publicKey ? publicKey.toBase58() : undefined,
statement: 'Please sign in.',
};
const output = await signIn(input);

notify('success', `Message signature: ${bs58.encode(signature)}`);
if (!verifySignIn(input, output)) throw new Error('Sign In verification failed!');
notify('success', `Message signature: ${bs58.encode(output.signature)}`);
} catch (error: any) {
notify('error', `Sign In failed: ${error?.message}`);
}
Expand Down

0 comments on commit aef5453

Please sign in to comment.