diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts
index 9f7041d4..0ccabd62 100644
--- a/src/util/entities/Channel.ts
+++ b/src/util/entities/Channel.ts
@@ -28,6 +28,7 @@ import {
import { DmChannelDTO } from "../dtos";
import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces";
import {
+ Config,
InvisibleCharacters,
Snowflake,
containsAll,
@@ -41,10 +42,14 @@ import { Invite } from "./Invite";
import { Message } from "./Message";
import { ReadState } from "./ReadState";
import { Recipient } from "./Recipient";
-import { PublicUserProjection, User } from "./User";
+import { APPersonButMore, PublicUserProjection, User } from "./User";
import { VoiceState } from "./VoiceState";
import { Webhook } from "./Webhook";
+import crypto from "crypto";
+import { promisify } from "util";
+const generateKeyPair = promisify(crypto.generateKeyPair);
+
export enum ChannelType {
GUILD_TEXT = 0, // a text channel within a guild
DM = 1, // a direct message between users
@@ -193,6 +198,12 @@ export class Channel extends BaseClass {
@Column()
default_thread_rate_limit_per_user: number = 0;
+ @Column()
+ publicKey: string;
+
+ @Column()
+ privateKey: string;
+
// TODO: DM channel
static async createChannel(
channel: Partial<Channel>,
@@ -303,6 +314,21 @@ export class Channel extends BaseClass {
: channel.position) || 0,
};
+ const { publicKey, privateKey } = await generateKeyPair("rsa", {
+ modulusLength: 4096,
+ publicKeyEncoding: {
+ type: "spki",
+ format: "pem",
+ },
+ privateKeyEncoding: {
+ type: "pkcs8",
+ format: "pem",
+ },
+ });
+
+ channel.publicKey = publicKey;
+ channel.privateKey = privateKey;
+
const ret = Channel.create(channel);
await Promise.all([
@@ -362,6 +388,18 @@ export class Channel extends BaseClass {
if (channel == null) {
name = trimSpecial(name);
+ const { publicKey, privateKey } = await generateKeyPair("rsa", {
+ modulusLength: 4096,
+ publicKeyEncoding: {
+ type: "spki",
+ format: "pem",
+ },
+ privateKeyEncoding: {
+ type: "pkcs8",
+ format: "pem",
+ },
+ });
+
channel = await Channel.create({
name,
type,
@@ -378,6 +416,8 @@ export class Channel extends BaseClass {
}),
),
nsfw: false,
+ publicKey,
+ privateKey,
}).save();
}
@@ -483,6 +523,31 @@ export class Channel extends BaseClass {
owner_id: this.owner_id || undefined,
};
}
+
+ toAP(): APPersonButMore {
+ const { webDomain } = Config.get().federation;
+
+ return {
+ "@context": "https://www.w3.org/ns/activitystreams",
+ type: "Group",
+ id: `https://${webDomain}/fed/channel/${this.id}`,
+ name: this.name,
+ preferredUsername: this.id,
+ summary: this.topic,
+ icon: undefined,
+ discoverable: true,
+
+ publicKey: {
+ id: `https://${webDomain}/fed/user/${this.id}#main-key`,
+ owner: `https://${webDomain}/fed/user/${this.id}`,
+ publicKeyPem: this.publicKey,
+ },
+
+ inbox: `https://${webDomain}/fed/channel/${this.id}/inbox`,
+ outbox: `https://${webDomain}/fed/channel/${this.id}/outbox`,
+ followers: `https://${webDomain}/fed/channel/${this.id}/followers`,
+ };
+ }
}
export interface ChannelPermissionOverwrite {
|