Skip to content

Commit

Permalink
Merge pull request #43 from Web3Auth/update-web3auth
Browse files Browse the repository at this point in the history
Update web3auth to v9
  • Loading branch information
AyushBherwani1998 authored Sep 26, 2024
2 parents 814616a + 08b1a70 commit 350b590
Show file tree
Hide file tree
Showing 10 changed files with 1,644 additions and 1,549 deletions.
2,926 changes: 1,411 additions & 1,515 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
"dependencies": {
"@gtm-support/vue-gtm": "^3.1.0",
"@mertasan/tailwindcss-variables": "^2.7.0",
"@toruslabs/ethereum-controllers": "^5.9.2",
"@toruslabs/openlogin-utils": "^8.2.1",
"@toruslabs/vue-components": "^7.8.3",
"@toruslabs/vue-icons": "^7.6.2",
"@walletconnect/sign-client": "^2.15.1",
"@web3auth/base": "^8.12.4",
"@web3auth/default-evm-adapter": "^8.12.4",
"@web3auth/ethereum-provider": "^8.12.4",
"@web3auth/modal": "^8.12.4",
"@web3auth/no-modal": "^8.12.4",
"@web3auth/openlogin-adapter": "^8.12.4",
"@web3auth/wallet-services-plugin": "^8.12.5",
"@web3auth/base": "^9.0.2",
"@web3auth/no-modal": "^9.1.0",
"bn.js": "^5.2.1",
"@toruslabs/ethereum-controllers": "^6.2.0",
"@toruslabs/vue-components": "^7.8.4",
"@toruslabs/vue-icons": "^7.6.2",
"@vueuse/core": "^10.9.0",
"@walletconnect/sign-client": "^2.16.2",
"@web3auth/default-evm-adapter": "^9.1.0",
"@web3auth/ethereum-provider": "^9.0.2",
"@web3auth/modal": "^9.1.0",
"@web3auth/auth-adapter": "^9.0.2",
"@web3auth/wallet-services-plugin": "^9.1.0",
"bowser": "^2.11.0",
"pinia": "^2.2.2",
"react": "^18.3.1",
Expand Down
196 changes: 196 additions & 0 deletions src/components/AuthDetails/AuthDetails.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<script setup lang="ts">
import { computed, onBeforeMount, ref } from 'vue'
import Bowser from 'bowser'
import { Button } from '@toruslabs/vue-components/Button'
import { Card } from '@toruslabs/vue-components/Card'
import { Divider } from '@toruslabs/vue-components/Divider'
import { Icon } from '@toruslabs/vue-components/Icon'
import { WALLET_ADAPTERS } from '@web3auth/base'
import CardHeading from '../CardHeading'

Check failure on line 11 in src/components/AuthDetails/AuthDetails.vue

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Cannot find module '../CardHeading' or its corresponding type declarations.
import { getBrowserName, getBrowserVersion } from '@/utils/common'

Check failure on line 12 in src/components/AuthDetails/AuthDetails.vue

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Module '"@/utils/common"' has no exported member 'getBrowserVersion'.
import { useWeb3authStore } from '@/store/web3authStore'
import type { AuthAdapter, AuthSessionData } from '@web3auth/auth-adapter'
const web3Auth = useWeb3authStore()
const FACTOR_MAP: Record<string, { title: string; icon?: string }> = {
device: { title: 'Saved in your device storage', icon: 'globe-alt-solid-icon' },
seedPhrase: { title: 'Saved as recovery phrase', icon: 'key-solid-icon' },
social: { title: 'Saved as a social recovery factor', icon: 'key-solid-icon' },
password: { title: 'Saved as a password', icon: 'key-solid-icon' }
}
const browserName = ref<string>('')
const browserVersion = ref<string>('')
const userInfo = computed(() => web3Auth.userInfo)
const isMfaEnabled = computed(() => web3Auth.userInfo?.isMfaEnabled)
const shareDetails = computed(() => {
const adapter = web3Auth.web3Auth?.walletAdapters[WALLET_ADAPTERS.AUTH] as AuthAdapter
const { shareDetails } = adapter.authInstance?.state as AuthSessionData & {
shareDetails: { shareType: string; details: string }[]
}
if (!shareDetails) return []
// Format shareDetails
return shareDetails.map((share) => {
let details = share.details
if (share.shareType === 'device') {
const browser = Bowser.getParser(share.details)
const browserDetails = browser.getBrowser()
details = `${browserDetails.name} ${browserDetails.version}`
}
return {
title: FACTOR_MAP[share.shareType].title,
details,
icon: FACTOR_MAP[share.shareType].icon
}
})
})
onBeforeMount(() => {
browserName.value = getBrowserName()
browserVersion.value = getBrowserVersion()
})
const handleHeadingBtnClick = () => {
window.open('https://web3auth.io/docs/pnp/features/mfa', '_blank')
}
const enableMfa = () => {
web3Auth.enableMfa()
}
</script>

<template>
<div>
<CardHeading
heading="Experience MPC Multi Factor Auth"
btn-label="Learn how progressive MFA works"
@on-click="handleHeadingBtnClick"
/>
<div>
<div>
<h1 class="text-xl md:text-2xl text-app-gray-800 font-semibold mb-7">
{{ isMfaEnabled ? 'Here’s a summary of what you set up' : 'What you will set up' }}
</h1>

<div class="ml-2 text-base">
<div class="flex items-center">
<div
class="mr-5 flex-shrink-0 flex items-center justify-center bg-app-primary-50 rounded-full w-6 h-6 font-medium"
>
1
</div>
<div>Your key is split into shares</div>
</div>
<div class="border-r border-app-gray-300 h-5 w-[13px] my-2"></div>
<div class="flex items-center">
<div
class="mr-5 flex-shrink-0 flex items-center justify-center bg-app-primary-50 rounded-full w-6 h-6 font-medium"
>
2
</div>
<div>Each key share is paired and stored with an authentication factor</div>
</div>
<div class="border-r border-app-gray-300 h-5 w-[13px] my-2"></div>
<div class="flex items-center">
<div
class="mr-5 flex-shrink-0 flex items-center justify-center bg-app-primary-50 rounded-full w-6 h-6 font-medium"
>
3
</div>
<div>
You need to verify at least 2 of these authentication factors to access your key
</div>
</div>
</div>

<Button
variant="secondary"
size="sm"
class="items-center gap-2 !border-app-gray-300 text-sm font-medium !text-app-gray-800 flex md:!hidden mt-6"
block
@on-click="handleHeadingBtnClick"
>
Learn how progressive MFA works <Icon name="arrow-right-icon" />
</Button>
</div>

<Divider class="mt-6 mb-4 mx-0" />

<h1
v-if="isMfaEnabled"
class="text-xl md:text-2xl text-app-gray-800 font-semibold mt-8 pt-6 md:pt-0"
>
Your Authentication Factors
</h1>

<div
v-if="isMfaEnabled"
class="flex flex-col md:grid grid-cols-3 items-center md:items-stretch justify-between gap-6 w-full pt-8"
>
<Card
class="flex flex-col flex-1 p-6 !rounded-2xl !shadow-none items-center w-full max-w-[240px] mx-auto"
>
<img src="@/assets/images/op-1.svg" class="h-16 w-16" />
<h4
class="leading-tight text-app-gray-900 text-base lg:text-lg font-semibold mt-5 text-center"
>
Paired with your social login
</h4>
<div
class="border border-app-gray-50 bg-app-gray-100 text-app-gray-500 text-xs xl:text-sm font-normal rounded-xl flex items-center gap-2 py-2 px-4 mt-8 w-full"
>
<Icon
v-if="['email_passwordless', 'jwt'].includes(userInfo?.typeOfLogin || '')"
name="mail-icon"
/>
<Icon v-else :name="`${userInfo?.typeOfLogin}-icon`" />
<p class="w-full truncate">{{ userInfo?.email || userInfo?.name }}</p>
</div>
</Card>
<Card
v-for="shareDetail in shareDetails"
:key="shareDetail.title"
class="flex flex-col flex-1 p-6 !rounded-2xl !shadow-none items-center w-full max-w-[240px] mx-auto"
>
<img src="@/assets/images/op-2.svg" class="h-16 w-16" />
<h4
class="leading-tight text-app-gray-900 text-base lg:text-lg font-semibold mt-5 text-center"
>
{{ shareDetail.title }}
</h4>
<div
class="border border-app-gray-50 bg-app-gray-100 text-app-gray-500 text-xs xl:text-sm font-normal rounded-xl flex items-center gap-2 py-2 px-4 mt-8 w-full"
>
<Icon v-if="shareDetail.icon" :name="shareDetail.icon" />
<p class="w-full truncate">{{ shareDetail.details }}</p>
</div>
</Card>
</div>
<div v-else>
<Icon name="lock-closed-solid-icon" size="28" class="text-app-gray-400 mb-4" />
<h2 class="text-xl text-app-gray-800 font-semibold mb-2">
Experience what it's like to configure MFA.
</h2>
<div class="text-app-gray-500 mb-4">
Configuring MFA is quick and easy, and it provides invaluable protection for your account.
</div>
<Button
variant="secondary"
size="xs"
:class="[
'flex items-center gap-2 !border-app-gray-300 !text-xs font-medium !text-app-gray-800 !w-full sm:!w-fit'
]"
@on-click="enableMfa"
id="w3a-set-up-mfa"
>Set up MFA
</Button>
</div>
</div>
</div>
</template>

<style scoped></style>
1 change: 1 addition & 0 deletions src/components/AuthDetails/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './AuthDetails.vue'
2 changes: 1 addition & 1 deletion src/components/LoginCard/LoginCard.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { useWeb3authStore } from '@/store/web3authStore'
import { LOGIN_PROVIDER } from '@web3auth/openlogin-adapter'
import { LOGIN_PROVIDER } from '@web3auth/auth-adapter'
import useCustomConfig from '@/composables/use-custom-config'
import useLocales from '@/composables/use-locales'
import { getUserCountry, validatePhoneNumber } from '@/utils/common'
Expand Down
6 changes: 3 additions & 3 deletions src/components/MfaDetails/MfaDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Icon } from '@toruslabs/vue-components/Icon'
import { computed } from 'vue'
import { useWeb3authStore } from '@/store/web3authStore'
import { WALLET_ADAPTERS } from '@web3auth/base'
import { OpenloginAdapter, OpenloginSessionData } from '@web3auth/openlogin-adapter'
import { AuthAdapter, AuthSessionData } from '@web3auth/auth-adapter'
import Bowser from 'bowser'
import Divider from '../Divider'
Expand All @@ -22,8 +22,8 @@ const userInfo = computed(() => web3Auth.userInfo)
const isMfaEnabled = computed(() => web3Auth.userInfo?.isMfaEnabled)
const shareDetails = computed(() => {
const adapter = web3Auth.web3Auth?.walletAdapters[WALLET_ADAPTERS.OPENLOGIN] as OpenloginAdapter
const { shareDetails } = adapter.openloginInstance?.state as OpenloginSessionData & {
const adapter = web3Auth.web3Auth?.walletAdapters[WALLET_ADAPTERS.AUTH] as AuthAdapter
const { shareDetails } = adapter.authInstance?.state as AuthSessionData & {
shareDetails: { shareType: string; details: string }[]
}
if (!shareDetails) return []
Expand Down
2 changes: 1 addition & 1 deletion src/components/WhiteLabelConfig/WhiteLabelConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link } from '@toruslabs/vue-components/Link'
import { Toggle } from '@toruslabs/vue-components/Toggle'
import { TextField } from '@toruslabs/vue-components/TextField'
import { Icon } from '@toruslabs/vue-components/Icon'
import { LANGUAGES, LANGUAGE_TYPE, applyWhiteLabelTheme } from '@web3auth/openlogin-adapter'
import { LANGUAGES, LANGUAGE_TYPE, applyWhiteLabelTheme } from '@web3auth/auth-adapter'
import useCustomConfig from '@/composables/use-custom-config'
import useLocales from '@/composables/use-locales'
Expand Down
27 changes: 11 additions & 16 deletions src/store/web3authStore.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import { MAINNET_CHAIN_ID, SUPPORTED_NETWORKS } from '@toruslabs/ethereum-controllers'
import { SafeEventEmitterProvider } from '@toruslabs/openlogin-jrpc'
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider'
import { Web3AuthNoModal } from '@web3auth/no-modal'
import { defineStore } from 'pinia'
import { ref, shallowRef, triggerRef, computed } from 'vue'
import { WalletServicesPlugin } from '@web3auth/wallet-services-plugin'
import {
OpenloginAdapter,
OpenloginLoginParams,
type OpenloginUserInfo
} from '@web3auth/openlogin-adapter'
import { AuthAdapter, type AuthUserInfo, type AuthLoginParams } from '@web3auth/auth-adapter'
import { useRouter } from 'vue-router'
import { ROUTES } from '@/constants/common'
import { WALLET_ADAPTERS } from '@web3auth/base'
import { CustomConfig } from '@/utils/interface'
import { WEB3AUTH_NETWORK, IProvider, WALLET_ADAPTERS } from '@web3auth/base'

export const useWeb3authStore = defineStore('web3auth', () => {
const web3Auth = shallowRef<Web3AuthNoModal | null>(null)
const provider = shallowRef<SafeEventEmitterProvider | null>(null)
const provider = shallowRef<IProvider | null>(null)
const walletServicesPlugin = shallowRef<WalletServicesPlugin | null>(null)

const router = useRouter()

const accounts = ref<string[]>([])
const userInfo = ref<Partial<OpenloginUserInfo> | null>(null)
const userInfo = ref<Partial<AuthUserInfo> | null>(null)

const isLoggingIn = ref(false)

Expand All @@ -42,7 +37,7 @@ export const useWeb3authStore = defineStore('web3auth', () => {
chainConfig,
clientId:
'BNI_pZZpoH4tqzbDDMKwfLOWujTif_kek4h9QEN271Gu0JheYDPEUHNKMl5Nnw5PGOjK-SOxp1RpUdG9TJufMZk',
web3AuthNetwork: 'sapphire_mainnet',
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
privateKeyProvider: privateKeyProvider,
uiConfig: {
mode: newConfig?.isDark ? 'dark' : 'light',
Expand All @@ -63,13 +58,13 @@ export const useWeb3authStore = defineStore('web3auth', () => {
}
})

const openloginAdapter = new OpenloginAdapter({
const authAdapter = new AuthAdapter({
privateKeyProvider,
adapterSettings: {
uxMode: 'popup'
}
})
web3Auth.value.configureAdapter(openloginAdapter)
web3Auth.value.configureAdapter(authAdapter)

walletServicesPlugin.value = new WalletServicesPlugin({
walletInitOptions: {
Expand Down Expand Up @@ -123,14 +118,14 @@ export const useWeb3authStore = defineStore('web3auth', () => {
loginProvider,
login_hint = ''
}: {
loginProvider: OpenloginLoginParams['loginProvider']
login_hint?: OpenloginLoginParams['login_hint']
loginProvider: AuthLoginParams['loginProvider']
login_hint?: AuthLoginParams['login_hint']
}) {
try {
console.log('logging', web3Auth.value)
isLoggingIn.value = true
const localProvider = await web3Auth.value?.connectTo<OpenloginLoginParams>(
WALLET_ADAPTERS.OPENLOGIN,
const localProvider = await web3Auth.value?.connectTo<AuthLoginParams>(
WALLET_ADAPTERS.AUTH,
{ loginProvider, login_hint }
)
console.log(localProvider, 'available')
Expand Down
2 changes: 1 addition & 1 deletion src/utils/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LANGUAGE_TYPE } from '@toruslabs/openlogin-utils'
import type { LANGUAGE_TYPE } from '@web3auth/auth-adapter'

export type CustomConfig = {
dappName: string
Expand Down
7 changes: 7 additions & 0 deletions src/views/Mpc.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
import AuthDetails from '@/components/AuthDetails';
</script>

<template>
<AuthDetails />
</template>

0 comments on commit 350b590

Please sign in to comment.