mirror of
https://github.com/logos-messaging/OpChan.git
synced 2026-01-02 12:53:10 +00:00
wip: mandate signatures
This commit is contained in:
parent
d43d3bfec7
commit
d8fe4a3dcc
@ -26,7 +26,8 @@ describe('RelevanceCalculator', () => {
|
||||
content: 'Test content',
|
||||
timestamp: Date.now(),
|
||||
upvotes: [],
|
||||
downvotes: []
|
||||
downvotes: [],
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const result = calculator.calculatePostScore(post, [], [], mockUserVerificationStatus);
|
||||
@ -45,7 +46,8 @@ describe('RelevanceCalculator', () => {
|
||||
content: 'Test content',
|
||||
timestamp: Date.now(),
|
||||
upvotes: [],
|
||||
downvotes: []
|
||||
downvotes: [],
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const result = calculator.calculatePostScore(post, [], [], mockUserVerificationStatus);
|
||||
@ -61,7 +63,8 @@ describe('RelevanceCalculator', () => {
|
||||
verificationStatus: EVerificationStatus.VERIFIED_OWNER,
|
||||
ensOwnership: true,
|
||||
ensName: 'test.eth',
|
||||
lastChecked: Date.now()
|
||||
lastChecked: Date.now(),
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const isVerified = calculator.isUserVerified(verifiedUser);
|
||||
@ -74,7 +77,8 @@ describe('RelevanceCalculator', () => {
|
||||
walletType: 'bitcoin',
|
||||
verificationStatus: EVerificationStatus.VERIFIED_OWNER,
|
||||
ordinalOwnership: true,
|
||||
lastChecked: Date.now()
|
||||
lastChecked: Date.now(),
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const isVerified = calculator.isUserVerified(verifiedUser);
|
||||
@ -87,7 +91,8 @@ describe('RelevanceCalculator', () => {
|
||||
walletType: 'ethereum',
|
||||
verificationStatus: EVerificationStatus.UNVERIFIED,
|
||||
ensOwnership: false,
|
||||
lastChecked: Date.now()
|
||||
lastChecked: Date.now(),
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const isVerified = calculator.isUserVerified(unverifiedUser);
|
||||
@ -104,7 +109,8 @@ describe('RelevanceCalculator', () => {
|
||||
timestamp: Date.now(),
|
||||
upvotes: [],
|
||||
downvotes: [],
|
||||
moderated: true
|
||||
moderated: true,
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const result = calculator.calculatePostScore(post, [], [], mockUserVerificationStatus);
|
||||
@ -122,16 +128,17 @@ describe('RelevanceCalculator', () => {
|
||||
content: 'Test content',
|
||||
timestamp: Date.now(),
|
||||
upvotes: [],
|
||||
downvotes: []
|
||||
downvotes: [],
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const votes: VoteMessage[] = [
|
||||
{ id: 'vote1', targetId: '1', value: 1, author: 'user1', timestamp: Date.now(), type: MessageType.VOTE },
|
||||
{ id: 'vote2', targetId: '1', value: 1, author: 'user3', timestamp: Date.now(), type: MessageType.VOTE }
|
||||
{ id: 'vote1', targetId: '1', value: 1, author: 'user1', timestamp: Date.now(), type: MessageType.VOTE, signature: 'signature' },
|
||||
{ id: 'vote2', targetId: '1', value: 1, author: 'user3', timestamp: Date.now(), type: MessageType.VOTE, signature: 'signature' }
|
||||
];
|
||||
|
||||
const comments: Comment[] = [
|
||||
{ id: 'comment1', postId: '1', authorAddress: 'user1', content: 'Test comment', timestamp: Date.now(), upvotes: [], downvotes: [] }
|
||||
{ id: 'comment1', postId: '1', authorAddress: 'user1', content: 'Test comment', timestamp: Date.now(), upvotes: [], downvotes: [], signature: 'signature' }
|
||||
];
|
||||
|
||||
const result = calculator.calculatePostScore(post, votes, comments, mockUserVerificationStatus);
|
||||
@ -156,7 +163,8 @@ describe('RelevanceCalculator', () => {
|
||||
content: 'Recent content',
|
||||
timestamp: now,
|
||||
upvotes: [],
|
||||
downvotes: []
|
||||
downvotes: [],
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const oldPost: Post = {
|
||||
@ -167,7 +175,8 @@ describe('RelevanceCalculator', () => {
|
||||
content: 'Old content',
|
||||
timestamp: oneWeekAgo,
|
||||
upvotes: [],
|
||||
downvotes: []
|
||||
downvotes: [],
|
||||
signature: 'signature'
|
||||
};
|
||||
|
||||
const recentResult = calculator.calculatePostScore(recentPost, [], [], mockUserVerificationStatus);
|
||||
@ -186,14 +195,16 @@ describe('RelevanceCalculator', () => {
|
||||
verificationStatus: EVerificationStatus.VERIFIED_OWNER,
|
||||
ensOwnership: true,
|
||||
ensName: 'test.eth',
|
||||
lastChecked: Date.now()
|
||||
lastChecked: Date.now(),
|
||||
signature: 'signature'
|
||||
},
|
||||
{
|
||||
address: 'user2',
|
||||
walletType: 'bitcoin',
|
||||
verificationStatus: EVerificationStatus.UNVERIFIED,
|
||||
ordinalOwnership: false,
|
||||
lastChecked: Date.now()
|
||||
lastChecked: Date.now(),
|
||||
signature: 'signature'
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@ -67,6 +67,7 @@ export const createPost = async (
|
||||
content,
|
||||
timestamp: Date.now(),
|
||||
author: currentUser.address,
|
||||
signature: currentUser.signature
|
||||
};
|
||||
|
||||
const cryptoService = new CryptoService();
|
||||
@ -134,11 +135,12 @@ export const createComment = async (
|
||||
const commentId = uuidv4();
|
||||
const commentMessage: CommentMessage = {
|
||||
type: MessageType.COMMENT,
|
||||
id: commentId,
|
||||
id: commentId,
|
||||
postId,
|
||||
content,
|
||||
timestamp: Date.now(),
|
||||
author: currentUser.address,
|
||||
signature: currentUser.signature
|
||||
};
|
||||
|
||||
const cryptoService = new CryptoService();
|
||||
@ -198,6 +200,7 @@ export const createCell = async (
|
||||
...(icon && { icon }),
|
||||
timestamp: Date.now(),
|
||||
author: currentUser.address,
|
||||
signature: currentUser.signature
|
||||
};
|
||||
|
||||
const cryptoService = new CryptoService();
|
||||
@ -275,6 +278,7 @@ export const vote = async (
|
||||
value: isUpvote ? 1 : -1,
|
||||
timestamp: Date.now(),
|
||||
author: currentUser.address,
|
||||
signature: currentUser.signature
|
||||
};
|
||||
|
||||
const cryptoService = new CryptoService();
|
||||
@ -342,6 +346,7 @@ export const moderatePost = async (
|
||||
reason,
|
||||
timestamp: Date.now(),
|
||||
author: currentUser.address,
|
||||
signature: currentUser.signature
|
||||
};
|
||||
const cryptoService = new CryptoService();
|
||||
const messageService = new MessageService(authService!, cryptoService);
|
||||
@ -392,6 +397,7 @@ export const moderateComment = async (
|
||||
reason,
|
||||
timestamp: Date.now(),
|
||||
author: currentUser.address,
|
||||
signature: currentUser.signature
|
||||
};
|
||||
const cryptoService = new CryptoService();
|
||||
const messageService = new MessageService(authService!, cryptoService);
|
||||
@ -439,7 +445,7 @@ export const moderateUser = async (
|
||||
reason,
|
||||
author: currentUser.address,
|
||||
timestamp: Date.now(),
|
||||
signature: '',
|
||||
signature: currentUser.signature,
|
||||
browserPubKey: currentUser.browserPubKey,
|
||||
};
|
||||
const cryptoService = new CryptoService();
|
||||
|
||||
@ -2,7 +2,7 @@ import { createDecoder, createEncoder } from '@waku/sdk';
|
||||
import { MessageType } from './types';
|
||||
import { CellMessage, PostMessage, CommentMessage, VoteMessage } from './types';
|
||||
import { CONTENT_TOPICS, NETWORK_CONFIG } from './constants';
|
||||
import { OpchanMessage } from '@/types';
|
||||
import { OpchanMessage } from '@/types/forum';
|
||||
|
||||
export const encoders = {
|
||||
[MessageType.CELL]: createEncoder({
|
||||
@ -21,6 +21,10 @@ export const encoders = {
|
||||
contentTopic: CONTENT_TOPICS['vote'],
|
||||
pubsubTopicShardInfo: {clusterId: NETWORK_CONFIG.clusterId, shard: 0}
|
||||
}),
|
||||
[MessageType.MODERATE]: createEncoder({
|
||||
contentTopic: CONTENT_TOPICS['moderate'],
|
||||
pubsubTopicShardInfo: {clusterId: NETWORK_CONFIG.clusterId, shard: 0}
|
||||
})
|
||||
}
|
||||
|
||||
export const decoders = {
|
||||
@ -40,6 +44,10 @@ export const decoders = {
|
||||
clusterId: NETWORK_CONFIG.clusterId,
|
||||
shard: 0
|
||||
}),
|
||||
[MessageType.MODERATE]: createDecoder(CONTENT_TOPICS['moderate'], {
|
||||
clusterId: NETWORK_CONFIG.clusterId,
|
||||
shard: 0
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { NetworkConfig } from "@waku/sdk";
|
||||
import { MessageType } from "./types";
|
||||
|
||||
/**
|
||||
@ -12,11 +11,11 @@ export const CONTENT_TOPICS: Record<MessageType, string> = {
|
||||
[MessageType.MODERATE]: '/opchan/1/moderate/proto'
|
||||
};
|
||||
|
||||
export const NETWORK_CONFIG: NetworkConfig = {
|
||||
export const NETWORK_CONFIG = {
|
||||
// contentTopics: Object.values(CONTENT_TOPICS),
|
||||
clusterId: 1,
|
||||
shards: [0,1,2,3,4,5,6,7]
|
||||
}
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Bootstrap nodes for the Waku network
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { LightNode } from "@waku/sdk";
|
||||
import { CellMessage, CommentMessage, MessageType, PostMessage, VoteMessage, ModerateMessage } from "./types";
|
||||
import { OpchanMessage } from "@/types";
|
||||
import { OpchanMessage } from "@/types/forum";
|
||||
import { encodeMessage, encoders, decoders, decodeMessage } from "./codec";
|
||||
|
||||
export class EphemeralProtocolsManager {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { IDecodedMessage } from '@waku/sdk';
|
||||
import { Cell, Post, Comment } from '@/types';
|
||||
import { OpchanMessage, Cell, Post, Comment } from '@/types/forum';
|
||||
import { CellMessage, CommentMessage, MessageType, PostMessage } from './types';
|
||||
import { OpchanMessage } from '@/types';
|
||||
// Utility functions for converting between message types and application models
|
||||
export function cellToMessage(cell: Cell, sender: string): CellMessage {
|
||||
return {
|
||||
@ -11,7 +10,8 @@ export function cellToMessage(cell: Cell, sender: string): CellMessage {
|
||||
id: cell.id,
|
||||
name: cell.name,
|
||||
description: cell.description,
|
||||
...(cell.icon && { icon: cell.icon })
|
||||
...(cell.icon && { icon: cell.icon }),
|
||||
signature: cell.signature,
|
||||
};
|
||||
}
|
||||
|
||||
@ -20,7 +20,8 @@ export function messageToCell(message: CellMessage): Cell {
|
||||
id: message.id,
|
||||
name: message.name,
|
||||
description: message.description,
|
||||
icon: message.icon || ''
|
||||
icon: message.icon || '',
|
||||
signature: message.signature,
|
||||
};
|
||||
}
|
||||
|
||||
@ -32,7 +33,8 @@ export function postToMessage(post: Post, sender: string): PostMessage {
|
||||
id: post.id,
|
||||
title: post.title,
|
||||
cellId: post.cellId,
|
||||
content: post.content
|
||||
content: post.content,
|
||||
signature: post.signature,
|
||||
};
|
||||
}
|
||||
|
||||
@ -45,7 +47,8 @@ export function messageToPost(message: PostMessage): Post {
|
||||
timestamp: message.timestamp,
|
||||
title: message.title,
|
||||
upvotes: [],
|
||||
downvotes: []
|
||||
downvotes: [],
|
||||
signature: message.signature,
|
||||
};
|
||||
}
|
||||
|
||||
@ -56,7 +59,8 @@ export function commentToMessage(comment: Comment, sender: string): CommentMessa
|
||||
author: sender,
|
||||
id: comment.id,
|
||||
postId: comment.postId,
|
||||
content: comment.content
|
||||
content: comment.content,
|
||||
signature: comment.signature,
|
||||
};
|
||||
}
|
||||
|
||||
@ -68,7 +72,8 @@ export function messageToComment(message: CommentMessage): Comment {
|
||||
content: message.content,
|
||||
timestamp: message.timestamp,
|
||||
upvotes: [],
|
||||
downvotes: []
|
||||
downvotes: [],
|
||||
signature: message.signature,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ export interface BaseMessage {
|
||||
type: MessageType;
|
||||
timestamp: number;
|
||||
author: string;
|
||||
signature?: string; // Message signature for verification
|
||||
signature: string; // Message signature for verification
|
||||
browserPubKey?: string; // Public key that signed the message
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ export interface User {
|
||||
|
||||
verificationStatus: EVerificationStatus;
|
||||
|
||||
signature?: string;
|
||||
signature: string;
|
||||
lastChecked?: number;
|
||||
browserPubKey?: string; // Browser-generated public key for key delegation
|
||||
delegationSignature?: string; // Signature from Bitcoin/Ethereum wallet for delegation
|
||||
@ -52,7 +52,7 @@ export interface Post {
|
||||
timestamp: number;
|
||||
upvotes: VoteMessage[];
|
||||
downvotes: VoteMessage[];
|
||||
signature?: string; // Message signature
|
||||
signature: string; // Message signature
|
||||
browserPubKey?: string; // Public key that signed the message
|
||||
moderated?: boolean;
|
||||
moderatedBy?: string;
|
||||
@ -72,7 +72,7 @@ export interface Comment {
|
||||
timestamp: number;
|
||||
upvotes: VoteMessage[];
|
||||
downvotes: VoteMessage[];
|
||||
signature?: string; // Message signature
|
||||
signature: string; // Message signature
|
||||
browserPubKey?: string; // Public key that signed the message
|
||||
moderated?: boolean;
|
||||
moderatedBy?: string;
|
||||
@ -84,7 +84,7 @@ export interface Comment {
|
||||
|
||||
// Extended message types for verification
|
||||
export interface SignedMessage {
|
||||
signature?: string; // Signature of the message
|
||||
signature: string; // Signature of the message
|
||||
browserPubKey?: string; // Public key that signed the message
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user