-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: encrypted chat #488
feat: encrypted chat #488
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
f202989
to
801e4a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it and it works quite well! I found two things that broke:
- when someone starts chatting with me (private chat), I am no longer redirected from the invite page to the chat
- If i already have private a chat with someone and I past the invite link, I am not redirected to that chat. Instead I see the invite screen with options
Start new chat
andDecline
@@ -35,6 +35,7 @@ export interface WakuObjectState { | |||
readonly exchangeRates: Map<string, ExchangeRateRecord> | |||
readonly fiatSymbol: FiatSymbol | |||
readonly chatName: string | |||
readonly chatType: ChatType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition!
src/lib/adapters/waku/crypto.ts
Outdated
export function hash(data: Uint8Array): Hex { | ||
const hashBytes = keccak_256(data) | ||
return bytesToHex(hashBytes) | ||
} | ||
|
||
export function hashHex(data: Hex): Hex { | ||
const bytes = hexToBytes(data) | ||
return hash(bytes) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be cleaner as single function that takes both Uint8Array
and Hex
types. It would make it easier to use in code.
export function hash(data: Uint8Array): Hex { | |
const hashBytes = keccak_256(data) | |
return bytesToHex(hashBytes) | |
} | |
export function hashHex(data: Hex): Hex { | |
const bytes = hexToBytes(data) | |
return hash(bytes) | |
} | |
export function hash(data: Hex | Uint8Array): Hex { | |
const bytes = typeof data === 'string' ? hexToBytes(data) | data | |
const hashBytes = keccak_256(data) | |
return bytesToHex(hashBytes) | |
} |
I fixed the second one. Regarding the first one, there is only a redirect if you are on the invite page (e.g. showing your QR code) otherwise it could be bad UX if the app would just redirect when you are typing in a different chat. On the invite page it is working for me, can you please check if it is working for you? |
src/lib/adapters/waku/index.ts
Outdated
const ownPublicKey = wallet.signingKey.compressedPublicKey | ||
|
||
const ownPublicEncryptionKey = hexToBytes(hashHex(ownPublicKey)) | ||
const ownPrivateEncryptionKey = hexToBytes(hashHex(wallet.privateKey)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work with external wallets like MetaMask. Not necessarily a huge problem, but good to keep in mind in case we want to support these at some point.
Also, what's the point of encrypting the localStorage
if you can just get the wallet's private key and decrypt it anyways? Or where is the wallet stored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point regarding external wallets.
When you disconnect the mnemonic is deleted from the localstorage, but your other data is not. This way if you are paranoid you can use the app by connecting with your mnemonic and disconnecting when you are done, but your data may stay in the localstorage and you can still keep you contacts etc. Or you can have multiple accounts and change between them easily.
The alternative would be to delete everything from the localstorage when you disconnect, but that would make multiple accounts less convenient, so I choose to use encryption instead.
This is a breaking change
Basic encrypted chat. When sharing an invite link the public key is shared instead of the address, therefore it is possible to create a shared secret with ECDH that is used as a symmetric encryption key. The waku topic is the hash of a value derived from the symmetric encryption key. The localStorage is also encrypted, both the keys and the values.
Known issues: