diff options
| author | d0x471b <0x471@protonmail.com> | 2022-12-31 03:45:30 +0300 |
|---|---|---|
| committer | d0x471b <0x471@protonmail.com> | 2022-12-31 03:45:30 +0300 |
| commit | 0f1d7d51de1baa21256fdb7ddafe54aab66172f7 (patch) | |
| tree | 30373f9b64ba6301096f26cdade55ebac4f5e59f /webapp/public/index.html | |
| parent | 517ad8d13a6b23328927154226575605be70669f (diff) | |
Diffstat (limited to 'webapp/public/index.html')
| -rw-r--r-- | webapp/public/index.html | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/webapp/public/index.html b/webapp/public/index.html new file mode 100644 index 0000000..fabc8a0 --- /dev/null +++ b/webapp/public/index.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<html> + +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title></title> + <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script> +</head> + +<body> + <button onclick="connect()">Login with Web3</button> + + <script type="text/javascript"> + let account = null; + let accessToken = null; + const connect = async () => { + if (window.ethereum) { + await window.ethereum.send('eth_requestAccounts') + window.w3 = new Web3(window.ethereum) + var accounts = await w3.eth.getAccounts() + account = accounts[0]; + + accessToken = await authenticate() + + let opts = { + method: 'GET', + headers: { + 'Content-Type': "application/json", + 'Authorization': `Bearer ${accessToken}` + } + } + + let res = await fetch(`/secret`, opts) + alert(await res.text()) + } + } + + const authenticate = async () => { + let res = await fetch(`/nonce?address=${account}`) + let resBody = await res.json() + + let signature = await w3.eth.personal.sign(resBody.message, account) + + let opts = { + method: 'POST', + headers: { + 'Content-Type': "application/json", + 'Authorization': `Bearer ${resBody.tempToken}` + } + } + + res = await fetch(`/verify?signature=${signature}`, opts) + resBody = await res.json() + + console.log(resBody) + return resBody.token + } + </script> +</body> + +</html>
\ No newline at end of file |
