feat: auth wallet multi address (#93)

* feat: updates auth wallet to be multi address compatible

* chore: updates `auth` to v2.0.0

* chore: updates `react-dapp-auth` to auth latest

* chore: updates `vue-dapp-auth` to auth latest
This commit is contained in:
Gancho Radkov 2022-12-16 13:43:40 +02:00 committed by GitHub
parent 21168541f2
commit 6aabae1762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 2829 additions and 1872 deletions

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
"@chakra-ui/react": "^2.2.6", "@chakra-ui/react": "^2.2.6",
"@emotion/react": "^11.10.0", "@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0", "@emotion/styled": "^11.10.0",
"@walletconnect/auth-client": "1.0.1", "@walletconnect/auth-client": "^2.0.0",
"better-sqlite3": "^7.6.2", "better-sqlite3": "^7.6.2",
"ethers": "^5.7.0", "ethers": "^5.7.0",
"events": "^3.3.0", "events": "^3.3.0",

View File

@ -16,7 +16,7 @@
"@nuxtjs/tailwindcss": "^6.1.3", "@nuxtjs/tailwindcss": "^6.1.3",
"@pinia/nuxt": "^0.4.3", "@pinia/nuxt": "^0.4.3",
"@vueuse/nuxt": "^9.1.1", "@vueuse/nuxt": "^9.1.1",
"@walletconnect/auth-client": "1.0.1", "@walletconnect/auth-client": "^2.0.0",
"ethers": "^5.7.0", "ethers": "^5.7.0",
"nuxt-icon": "^0.1.7", "nuxt-icon": "^0.1.7",
"pinia": "^2.0.23", "pinia": "^2.0.23",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
"@nextui-org/react": "1.0.8-beta.5", "@nextui-org/react": "1.0.8-beta.5",
"@polkadot/keyring": "^10.1.2", "@polkadot/keyring": "^10.1.2",
"@solana/web3.js": "1.43.0", "@solana/web3.js": "1.43.0",
"@walletconnect/auth-client": "1.0.1", "@walletconnect/auth-client": "^2.0.0",
"@walletconnect/utils": "2.0.0", "@walletconnect/utils": "2.0.0",
"bs58": "5.0.0", "bs58": "5.0.0",
"cosmos-wallet": "1.2.0", "cosmos-wallet": "1.2.0",

View File

@ -9,11 +9,8 @@ export default function useInitialization() {
const onInitialize = useCallback(async () => { const onInitialize = useCallback(async () => {
try { try {
const { eip155Addresses } = createOrRestoreEIP155Wallet() const { eip155Addresses } = createOrRestoreEIP155Wallet()
SettingsStore.setEIP155Address(eip155Addresses[0]) SettingsStore.setEIP155Address(eip155Addresses[0])
await createAuthClient()
await createAuthClient(eip155Addresses[0])
setInitialized(true) setInitialized(true)
} catch (err: unknown) { } catch (err: unknown) {
alert(err) alert(err)

View File

@ -5,11 +5,10 @@ console.log(`AuthClient@${pkg.version}`)
export let authClient: AuthClient export let authClient: AuthClient
export async function createAuthClient(address: string) { export async function createAuthClient() {
authClient = await AuthClient.init({ authClient = await AuthClient.init({
projectId: process.env.NEXT_PUBLIC_PROJECT_ID!, projectId: process.env.NEXT_PUBLIC_PROJECT_ID!,
relayUrl: process.env.NEXT_PUBLIC_RELAY_URL || 'wss://relay.walletconnect.com', relayUrl: process.env.NEXT_PUBLIC_RELAY_URL || 'wss://relay.walletconnect.com',
iss: `did:pkh:eip155:1:${address}`,
metadata: { metadata: {
name: 'React Wallet', name: 'React Wallet',
description: 'React Wallet for WalletConnect', description: 'React Wallet for WalletConnect',

View File

@ -1,4 +1,4 @@
import { Fragment } from 'react' import { Fragment, useCallback, useEffect, useState } from 'react'
import RequestModalContainer from '@/components/RequestModalContainer' import RequestModalContainer from '@/components/RequestModalContainer'
import ModalStore from '@/store/ModalStore' import ModalStore from '@/store/ModalStore'
import { Button, Col, Divider, Modal, Row, Text } from '@nextui-org/react' import { Button, Col, Divider, Modal, Row, Text } from '@nextui-org/react'
@ -7,29 +7,42 @@ import { authClient } from '@/utils/WalletConnectUtil'
export default function AuthenticationRequestModal() { export default function AuthenticationRequestModal() {
const authenticationRequest = ModalStore.state.data?.authenticationRequest const authenticationRequest = ModalStore.state.data?.authenticationRequest
const { params, id } = authenticationRequest
const [message, setMessage] = useState<string>()
const [iss, setIss] = useState<string>()
const { eip155Wallets, eip155Addresses } = createOrRestoreEIP155Wallet()
useEffect(() => {
if (message) return
const address = eip155Addresses[0]
const iss = `did:pkh:eip155:1:${address}`
setMessage(authClient.formatMessage(authenticationRequest.params.cacaoPayload, iss))
setIss(iss)
}, [authenticationRequest.params.cacaoPayload, eip155Addresses, message])
const onApprove = useCallback(async () => {
if (authenticationRequest && iss && message) {
console.log({ eip155Wallets })
const signature = await eip155Wallets[eip155Addresses[0]].signMessage(message)
await authClient.respond(
{
id,
signature: {
s: signature,
t: 'eip191'
}
},
iss
)
ModalStore.close()
}
}, [authenticationRequest, eip155Addresses, eip155Wallets, id, iss, message])
if (!authenticationRequest) { if (!authenticationRequest) {
return <Text>Missing authentication request</Text> return <Text>Missing authentication request</Text>
} }
const { params, id } = authenticationRequest
async function onApprove() {
if (authenticationRequest) {
const { eip155Wallets, eip155Addresses } = createOrRestoreEIP155Wallet()
console.log({ eip155Wallets })
const signature = await eip155Wallets[eip155Addresses[0]].signMessage(params.message)
await authClient.respond({
id,
signature: {
s: signature,
t: 'eip191'
}
})
ModalStore.close()
}
}
// Handle reject action // Handle reject action
async function onReject() { async function onReject() {
ModalStore.close() ModalStore.close()
@ -42,7 +55,7 @@ export default function AuthenticationRequestModal() {
<Col> <Col>
<Text h5>Message</Text> <Text h5>Message</Text>
<Text style={{ whiteSpace: 'pre-wrap' }} color="$gray400"> <Text style={{ whiteSpace: 'pre-wrap' }} color="$gray400">
{params.message} {message}
</Text> </Text>
</Col> </Col>
</Row> </Row>