From 854779ec244274cffe04182d5fa8b1fcb74096e7 Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Tue, 30 Apr 2024 16:13:04 -0600 Subject: [PATCH] feat: consent proof updates Updated consent proof handling to be on the updateV2Conversations method instead --- src/conversations/Conversation.ts | 10 +++++----- src/conversations/Conversations.ts | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/conversations/Conversation.ts b/src/conversations/Conversation.ts index 157280d22..340c3f542 100644 --- a/src/conversations/Conversation.ts +++ b/src/conversations/Conversation.ts @@ -1,10 +1,10 @@ import { message, content as proto, + type invitation, type keystore, type messageApi, } from '@xmtp/proto' -import type { ConsentProofPayload } from '@xmtp/proto/ts/dist/types/message_contents/invitation.pb' import { getAddress } from 'viem' import type { OnConnectionLostCallback } from '@/ApiClient' import type { @@ -89,7 +89,7 @@ export interface Conversation { /** * Proof of consent for the conversation, used when a user has pre-consented to a conversation */ - consentProof?: ConsentProofPayload + consentProof?: invitation.ConsentProofPayload /** * Retrieve messages in this conversation. Default to returning all messages. @@ -508,7 +508,7 @@ export class ConversationV2 peerAddress: string createdAt: Date context?: InvitationContext - consentProof?: ConsentProofPayload + consentProof?: invitation.ConsentProofPayload constructor( client: Client, @@ -516,7 +516,7 @@ export class ConversationV2 peerAddress: string, createdAt: Date, context: InvitationContext | undefined, - consentProof: ConsentProofPayload | undefined + consentProof: invitation.ConsentProofPayload | undefined ) { this.topic = topic this.createdAt = createdAt @@ -550,7 +550,7 @@ export class ConversationV2 return this.client.contacts.consentState(this.peerAddress) } - get consentProofPayload(): ConsentProofPayload | undefined { + get consentProofPayload(): invitation.ConsentProofPayload | undefined { return this.consentProof } diff --git a/src/conversations/Conversations.ts b/src/conversations/Conversations.ts index 1c3b9165b..b2cecf9b6 100644 --- a/src/conversations/Conversations.ts +++ b/src/conversations/Conversations.ts @@ -156,17 +156,25 @@ export default class Conversations { startTime, direction: SortDirection.SORT_DIRECTION_ASCENDING, }) - - return this.decodeInvites(envelopes) + const newConversations = await this.decodeInvites(envelopes) + newConversations.forEach((convo) => { + if (convo.consentProofPayload) { + this.handleConsentProof(convo.consentProofPayload, convo.peerAddress) + } + }) + return newConversations } private async validateConsentSignature( signature: `0x${string}`, - timestamp: number, + timestampMs: number, peerAddress: string ): Promise { const signatureData = splitSignature(signature) - const message = WalletSigner.consentProofRequestText(peerAddress, timestamp) + const message = WalletSigner.consentProofRequestText( + peerAddress, + timestampMs + ) const digest = hexToBytes(hashMessage(message)) // Recover public key const publicKey = ecdsaSignerKey(digest, signatureData) @@ -209,12 +217,6 @@ export default class Conversations { const out: ConversationV2[] = [] for (const response of responses) { try { - if (response.result?.conversation?.consentProofPayload) { - this.handleConsentProof( - response.result.conversation.consentProofPayload, - response.result.conversation.peerAddress - ) - } out.push(this.saveInviteResponseToConversation(response)) } catch (e) { console.warn('Error saving invite response to conversation: ', e)