Skip to content

Commit

Permalink
feat: Lowercase Address handling
Browse files Browse the repository at this point in the history
Added handling to ensure addresses are checksums
  • Loading branch information
Alex Risch authored and Alex Risch committed Feb 2, 2024
1 parent c68bcc5 commit ed8f7cc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
33 changes: 33 additions & 0 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,5 +890,38 @@ test('correctly handles lowercase addresses', async () => {
if (!aliceConversation) {
throw new Error('aliceConversation should exist')
}

await bob.contacts.deny([aliceConversation.peerAddress.toLocaleLowerCase()])
await delayToPropogate()
const deniedState = await bob.contacts.isDenied(aliceConversation.peerAddress)
const allowedState = await bob.contacts.isAllowed(
aliceConversation.peerAddress
)
if (!deniedState) {
throw new Error(`contacts denied by bo should be denied not ${deniedState}`)
}

if (allowedState) {
throw new Error(
`contacts denied by bo should be denied not ${allowedState}`
)
}
const deniedLowercaseState = await bob.contacts.isDenied(
aliceConversation.peerAddress.toLocaleLowerCase()
)
const allowedLowercaseState = await bob.contacts.isAllowed(
aliceConversation.peerAddress.toLocaleLowerCase()
)
if (!deniedLowercaseState) {
throw new Error(
`contacts denied by bo should be denied not ${deniedLowercaseState}`
)
}

if (allowedLowercaseState) {
throw new Error(
`contacts denied by bo should be denied not ${allowedLowercaseState}`
)
}
return true
})
17 changes: 13 additions & 4 deletions src/lib/Contacts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client } from './Client'
import { ConsentListEntry } from './ConsentListEntry'
import * as XMTPModule from '../index'
import { getAddress } from '../utils/address'

export default class Contacts {
client: Client<any>
Expand All @@ -10,19 +11,27 @@ export default class Contacts {
}

async isAllowed(address: string): Promise<boolean> {
return await XMTPModule.isAllowed(this.client.address, address)
return await XMTPModule.isAllowed(this.client.address, getAddress(address))
}

async isDenied(address: string): Promise<boolean> {
return await XMTPModule.isDenied(this.client.address, address)
return await XMTPModule.isDenied(this.client.address, getAddress(address))
}

async deny(addresses: string[]): Promise<void> {
return await XMTPModule.denyContacts(this.client.address, addresses)
const checkSummedAddresses = addresses.map((address) => getAddress(address))
return await XMTPModule.denyContacts(
this.client.address,
checkSummedAddresses
)
}

async allow(addresses: string[]): Promise<void> {
return await XMTPModule.allowContacts(this.client.address, addresses)
const checkSummedAddresses = addresses.map((address) => getAddress(address))
return await XMTPModule.allowContacts(
this.client.address,
checkSummedAddresses
)
}

async refreshConsentList(): Promise<ConsentListEntry[]> {
Expand Down

0 comments on commit ed8f7cc

Please sign in to comment.