Skip to content

Commit

Permalink
fix: change pairing flow
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Apr 9, 2024
1 parent 5ee0f66 commit 1744f23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/chrome/dapp/dapp-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const ChromeDAppClient = (logger: AppLogger) => {
if (message.interactionId) {
logger.warn({ reason: 'UnrecognizedDappRequest', message })
return onDappRequest(addOriginToWalletInteraction(message))
}
}
})
}

Expand Down
10 changes: 5 additions & 5 deletions src/pairing/pairing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { logger } from 'utils/logger'
import { config, radixConnectConfig } from 'config'
import { useConnectionsClient } from './state/connections'
import { useConnectorOptions } from './state/options'
import { Subscription, filter, map, tap, withLatestFrom } from 'rxjs'
import { Subscription, combineLatest, filter, map, switchMap, tap } from 'rxjs'
import { useNavigate } from 'react-router-dom'
import { blakeHashBufferToHex } from 'crypto/blake2b'
import { ed25519 } from '@noble/curves/ed25519'
import { getLinkingSignatureMessage } from 'crypto/get-linking-message'

Expand Down Expand Up @@ -70,10 +69,11 @@ export const Pairing = () => {
connectorClient.connected$
.pipe(
filter(Boolean),
withLatestFrom(hexConnectionPassword$),
withLatestFrom(linkClientInteraction$),
switchMap(() =>
combineLatest([hexConnectionPassword$, linkClientInteraction$]),
),
)
.subscribe(([[, password], interaction]) => {
.subscribe(([password, interaction]) => {
connectionsClient
.addOrUpdate(password, interaction)
.map(() => connectorClient.disconnect())
Expand Down
13 changes: 8 additions & 5 deletions src/pairing/state/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,16 @@ const ConnectionsClient = (connections?: Connections | null) => {
const addOrUpdate = (password: string, interaction: Message) => {
const walletPublickey = interaction.publicKey
const signature = interaction.signature
const message = getLinkingSignatureMessage(Buffer.from(password, 'hex'))
const validSignature = ed25519.verify(signature, message, walletPublickey)
if (signature) {
const message = getLinkingSignatureMessage(Buffer.from(password, 'hex'))
const validSignature = ed25519.verify(signature, message, walletPublickey)

if (!validSignature) {
logger.warn('Invalid Signature')
// return errAsync({ cause: 'Invalid Signature' } as Error)
if (!validSignature) {
logger.warn('Invalid Signature')
// return errAsync({ cause: 'Invalid Signature' } as Error)
}
}

if (connections && connections[walletPublickey]) {
connections[walletPublickey] = {
...connections[walletPublickey],
Expand Down

0 comments on commit 1744f23

Please sign in to comment.