OpChan/src/types/waku.ts

170 lines
3.9 KiB
TypeScript
Raw Normal View History

2025-09-05 12:53:15 +05:30
import { EDisplayPreference, EVerificationStatus } from './identity';
2025-09-04 13:27:47 +05:30
/**
* Message types for Waku communication
*/
export enum MessageType {
CELL = 'cell',
POST = 'post',
COMMENT = 'comment',
VOTE = 'vote',
MODERATE = 'moderate',
2025-09-03 15:01:57 +05:30
USER_PROFILE_UPDATE = 'user_profile_update',
}
/**
2025-08-30 18:34:50 +05:30
* Base interface for unsigned messages (before signing)
*/
2025-08-30 18:34:50 +05:30
export interface UnsignedBaseMessage {
2025-08-29 16:16:20 +05:30
id: string;
type: MessageType;
2025-08-30 18:34:50 +05:30
timestamp: number; // Unix timestamp in milliseconds
author: string;
}
/**
2025-08-30 18:34:50 +05:30
* Base interface for all signed message types
*/
2025-08-30 18:34:50 +05:30
export interface BaseMessage extends UnsignedBaseMessage {
signature: string; // Message signature for verification
browserPubKey: string; // Public key that signed the message
}
/**
* Unsigned message types (for creation, before signing)
*/
export interface UnsignedCellMessage extends UnsignedBaseMessage {
type: MessageType.CELL;
name: string;
description: string;
icon?: string;
}
2025-08-30 18:34:50 +05:30
export interface UnsignedPostMessage extends UnsignedBaseMessage {
type: MessageType.POST;
cellId: string;
title: string;
content: string;
}
export interface UnsignedCommentMessage extends UnsignedBaseMessage {
type: MessageType.COMMENT;
postId: string;
content: string;
}
export interface UnsignedVoteMessage extends UnsignedBaseMessage {
type: MessageType.VOTE;
targetId: string; // ID of the post or comment being voted on
value: 1 | -1;
}
export interface UnsignedModerateMessage extends UnsignedBaseMessage {
type: MessageType.MODERATE;
cellId: string;
targetType: 'post' | 'comment' | 'user';
targetId: string; // postId, commentId, or user address (for user moderation)
reason?: string;
}
2025-09-03 15:01:57 +05:30
export interface UnsignedUserProfileUpdateMessage extends UnsignedBaseMessage {
type: MessageType.USER_PROFILE_UPDATE;
callSign?: string;
2025-09-05 16:06:30 +05:30
displayPreference: EDisplayPreference;
2025-09-03 15:01:57 +05:30
}
/**
2025-08-30 18:34:50 +05:30
* Signed message types (after signature is added)
*/
2025-08-30 18:34:50 +05:30
export interface CellMessage extends BaseMessage {
type: MessageType.CELL;
name: string;
description: string;
icon?: string;
}
export interface PostMessage extends BaseMessage {
type: MessageType.POST;
cellId: string;
title: string;
content: string;
}
export interface CommentMessage extends BaseMessage {
type: MessageType.COMMENT;
postId: string;
content: string;
}
export interface VoteMessage extends BaseMessage {
type: MessageType.VOTE;
targetId: string; // ID of the post or comment being voted on
2025-08-30 18:34:50 +05:30
value: 1 | -1;
}
export interface ModerateMessage extends BaseMessage {
type: MessageType.MODERATE;
cellId: string;
targetType: 'post' | 'comment' | 'user';
targetId: string; // postId, commentId, or user address (for user moderation)
reason?: string;
}
2025-09-03 15:01:57 +05:30
export interface UserProfileUpdateMessage extends BaseMessage {
type: MessageType.USER_PROFILE_UPDATE;
callSign?: string;
2025-09-04 13:27:47 +05:30
displayPreference: EDisplayPreference;
2025-09-03 15:01:57 +05:30
}
2025-08-30 18:34:50 +05:30
/**
* Union types for message handling
*/
export type UnsignedMessage =
| UnsignedCellMessage
| UnsignedPostMessage
| UnsignedCommentMessage
| UnsignedVoteMessage
2025-09-03 15:01:57 +05:30
| UnsignedModerateMessage
| UnsignedUserProfileUpdateMessage;
2025-08-30 18:34:50 +05:30
export type SignedMessage =
| CellMessage
| PostMessage
| CommentMessage
| VoteMessage
2025-09-03 15:01:57 +05:30
| ModerateMessage
| UserProfileUpdateMessage;
2025-08-30 18:34:50 +05:30
/**
* Cache objects for storing messages
*/
export interface CellCache {
[cellId: string]: CellMessage;
}
export interface PostCache {
[postId: string]: PostMessage;
}
export interface CommentCache {
[commentId: string]: CommentMessage;
}
export interface VoteCache {
[key: string]: VoteMessage; // key = targetId + authorAddress
2025-08-30 18:34:50 +05:30
}
2025-09-03 15:01:57 +05:30
export interface UserIdentityCache {
[address: string]: {
ensName?: string;
ordinalDetails?: {
ordinalId: string;
ordinalDetails: string;
};
callSign?: string;
2025-09-05 12:53:15 +05:30
displayPreference: EDisplayPreference;
2025-09-03 15:01:57 +05:30
lastUpdated: number;
2025-09-05 12:53:15 +05:30
verificationStatus: EVerificationStatus;
2025-09-03 15:01:57 +05:30
};
}