-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #783 from solana-labs/sign-in
Sign In With Solana
- Loading branch information
Showing
21 changed files
with
222 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@solana/wallet-adapter-material-ui-starter': patch | ||
'@solana/wallet-adapter-react-ui-starter': patch | ||
'@solana/wallet-adapter-unsafe-burner': patch | ||
'@solana/wallet-adapter-example': patch | ||
'@solana/wallet-adapter-react': patch | ||
'@solana/wallet-adapter-base': patch | ||
--- | ||
|
||
Add `signIn` (Sign In With Solana) method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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, publicKey } = useWallet(); | ||
const notify = useNotify(); | ||
|
||
const onClick = useCallback(async () => { | ||
try { | ||
if (!signIn) throw new Error('Wallet does not support Sign In With Solana!'); | ||
|
||
const input: SolanaSignInInput = { | ||
domain: window.location.host, | ||
address: publicKey ? publicKey.toBase58() : undefined, | ||
statement: 'Please sign in.', | ||
}; | ||
const output = await signIn(input); | ||
|
||
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}`); | ||
} | ||
}, [signIn, publicKey, notify]); | ||
|
||
return ( | ||
<Button variant="contained" color="secondary" onClick={onClick} disabled={!signIn}> | ||
Sign In | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.