Skip to content

Commit

Permalink
fix: Session id updates (#247)
Browse files Browse the repository at this point in the history
* fix: remove `removeSessionId` command

* fix: stop requiring signature

* fix: change pairing flow
  • Loading branch information
dawidsowardx authored Apr 9, 2024
1 parent 8bc59dd commit 10b6574
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 32 deletions.
11 changes: 0 additions & 11 deletions src/chrome/background/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ export const BackgroundMessageHandler =
.mapErr(() => ({ reason: 'failedToFocusLedgerTab' }))
}

case messageDiscriminator.removeSessionId: {
chromeLocalStore.getSingleItem('sessionRouter').andThen((data) => {
if (!data) {
return okAsync(undefined)
}

const { [message.sessionId]: _, ...rest } = data
return chromeLocalStore.setSingleItem('sessionRouter', rest)
})
}

case messageDiscriminator.walletResponse: {
const sessionId = message.data?.metadata?.sessionId
const walletPublicKey = message.data?.metadata?.walletPublicKey
Expand Down
6 changes: 0 additions & 6 deletions src/chrome/content-script/content-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ const handleExtensionInteraction = async (
extensionInteraction: ExtensionInteraction,
) => {
switch (extensionInteraction.discriminator) {
case 'removeSessionId':
await sendMessage(
createMessage.removeSessionId(extensionInteraction.sessionId),
)
break

case 'openPopup':
await sendMessage(createMessage.openParingPopup())
break
Expand Down
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
1 change: 0 additions & 1 deletion src/chrome/messages/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const messageDiscriminator = {
getExtensionOptions: 'getExtensionOptions',
getSessionRouterData: 'getSessionRouterData',
setSessionRouterData: 'setSessionRouterData',
removeSessionId: 'removeSessionId',
dAppRequest: 'dAppRequest',
closeLedgerTab: 'closeLedgerTab',
focusLedgerTab: 'focusLedgerTab',
Expand Down
4 changes: 0 additions & 4 deletions src/chrome/messages/create-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export const createMessage = {
discriminator: messageDiscriminator.setSessionRouterData,
data,
}),
removeSessionId: (sessionId: string) => ({
discriminator: messageDiscriminator.removeSessionId,
sessionId,
}),
extensionStatus: (isWalletLinked: boolean) => ({
eventType: 'extensionStatus',
isExtensionAvailable: true,
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: 9 additions & 4 deletions src/pairing/state/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Message } from 'chrome/messages/_types'
import { chrome } from 'jest-chrome'
import { err, errAsync } from 'neverthrow'
import { useEffect, useState } from 'react'
import { logger } from 'utils/logger'

export type Connection = {
walletName: string
Expand Down Expand Up @@ -84,12 +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) {
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 10b6574

Please sign in to comment.