Skip to content

Commit 5b219c2

Browse files
committed
minor tweaks
1 parent f7c8519 commit 5b219c2

File tree

7 files changed

+160
-12
lines changed

7 files changed

+160
-12
lines changed

packages/frontend/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.tsbuildinfo
22
dist
33
node_modules
4+
stats.html

packages/frontend/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
},
1414
"devDependencies": {
1515
"@iexec/dataprotector": "2.0.0-beta.10",
16+
"@noble/hashes": "1.3.2",
1617
"@vitejs/plugin-vue": "^5.1.4",
1718
"@vueuse/core": "^11.1.0",
1819
"@web3modal/base": "^5.1.11",
1920
"@web3modal/ethers": "^5.1.11",
2021
"@web3modal/scaffold-utils": "^5.1.11",
2122
"ethers": "^6.13.4",
23+
"rollup-plugin-visualizer": "^5.12.0",
2224
"typescript": "^5.5.3",
2325
"vite": "^5.4.9",
2426
"vue-tsc": "^2.1.6"

packages/frontend/src/LoginGated.vue

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<script setup lang="ts">
22
import SIWEButton from './components/SIWEButton.vue';
3-
import {siweDerivedKey} from './login';
3+
import {isLoggedIn} from './login';
44
</script>
55
<!-- Displays the 'Connect' then 'Sign-in' buttons, before showing content -->
66
<template>
7-
<slot v-if="siweDerivedKey !== undefined"></slot>
7+
<slot v-if="isLoggedIn"></slot>
88
<div v-else>
9-
<w3m-button id="w3mbutton" />
10-
<SIWEButton />
9+
<div>
10+
<div>
11+
<h2>1: Connect Wallet</h2>
12+
<w3m-button style="margin: 0 auto;" />
13+
</div>
14+
<br />
15+
<div>
16+
<h2>2: Sign in with Ethereum</h2>
17+
<SIWEButton />
18+
</div>
19+
</div>
1120
</div>
1221
</template>

packages/frontend/src/components/SIWEButton.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { computed, ref, toValue } from 'vue';
2+
import { computed, toValue } from 'vue';
33
import { ethersBrowserProvider } from '../wallet';
44
import { useSIWE } from '../login';
55

packages/frontend/src/login.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import { computed, ref, toValue, watch } from "vue";
22
import { ethersBrowserProvider, modal } from './wallet';
3-
import { getBytes, keccak256 } from "ethers";
3+
import { getBytes } from "ethers";
4+
import { hmac } from '@noble/hashes/hmac';
5+
import { keccak_256 } from '@noble/hashes/sha3';
46

5-
export const siweDerivedKey = ref<string>();
7+
const siweDerivedKey = ref<Uint8Array>();
68
const lastAddress = ref<string>();
79

10+
export const isLoggedIn = computed(() => toValue(siweDerivedKey) !== undefined);
11+
12+
export function deriveKey(namespace:string) {
13+
const dk = toValue(siweDerivedKey);
14+
if( ! dk ) {
15+
throw new Error('Not logged in');
16+
}
17+
return hmac(keccak_256, dk, new TextEncoder().encode(namespace));
18+
}
19+
820
watch(ethersBrowserProvider, async (bp) => {
921
if( ! bp ) {
1022
siweDerivedKey.value = undefined;
@@ -55,12 +67,12 @@ export function useSIWE() {
5567
catch(e:any) {
5668
return false;
5769
}
58-
siweDerivedKey.value = keccak256(getBytes(result));
70+
siweDerivedKey.value = keccak_256(getBytes(result));
5971
}
6072
return {
6173
canSign,
6274
isSuccess,
6375
isSigning,
6476
doLogin
6577
};
66-
}
78+
}

packages/frontend/vite.config.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { defineConfig } from 'vite'
2-
import vue from '@vitejs/plugin-vue'
1+
import { defineConfig } from 'vite';
2+
import vue from '@vitejs/plugin-vue';
3+
import { visualizer } from 'rollup-plugin-visualizer'
34

45
// https://vite.dev/config/
56
export default defineConfig({
6-
plugins: [vue()],
7+
plugins: [
8+
vue(),
9+
visualizer()
10+
],
711
base: './',
812
});

0 commit comments

Comments
 (0)