diff --git a/dht-node/src/dht_node/index.ts b/dht-node/src/dht_node/index.ts index 004fc816e..dddebbfc7 100644 --- a/dht-node/src/dht_node/index.ts +++ b/dht-node/src/dht_node/index.ts @@ -24,6 +24,8 @@ type CommunityApi = { url: string } +type KeyPair = { publicKey: Buffer; secretKey: Buffer } + export const startDHT = async (topic: string): Promise => { try { const TOPIC = DHT.hash(Buffer.from(topic)) @@ -32,11 +34,11 @@ export const startDHT = async (topic: string): Promise => { CONFIG.FEDERATION_DHT_SEED ? Buffer.alloc(KEY_SECRET_SEEDBYTES, CONFIG.FEDERATION_DHT_SEED) : null, - ) + ) as KeyPair const pubKeyString = keyPair.publicKey.toString('hex') logger.info(`keyPairDHT: publicKey=${pubKeyString}`) logger.debug(`keyPairDHT: secretKey=${keyPair.secretKey.toString('hex')}`) - await writeHomeCommunityEntry(pubKeyString) + await writeHomeCommunityEntry(keyPair) const ownApiVersions = await writeFederatedHomeCommunityEntries(pubKeyString) logger.info(`ApiList: ${JSON.stringify(ownApiVersions)}`) @@ -212,13 +214,13 @@ async function writeFederatedHomeCommunityEntries(pubKey: string): Promise { +async function writeHomeCommunityEntry(keyPair: KeyPair): Promise { try { // check for existing homeCommunity entry let homeCom = await DbCommunity.findOne({ foreign: false }) if (homeCom) { // simply update the existing entry, but it MUST keep the ID and UUID because of possible relations - homeCom.publicKey = Buffer.from(pubKey) + homeCom.publicKey = keyPair.publicKey homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/' homeCom.name = CONFIG.COMMUNITY_NAME homeCom.description = CONFIG.COMMUNITY_DESCRIPTION @@ -228,7 +230,7 @@ async function writeHomeCommunityEntry(pubKey: string): Promise { // insert a new homecommunity entry including a new ID and a new but ensured unique UUID homeCom = new DbCommunity() homeCom.foreign = false - homeCom.publicKey = Buffer.from(pubKey) + homeCom.publicKey = keyPair.publicKey homeCom.communityUuid = await newCommunityUuid() homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/' homeCom.name = CONFIG.COMMUNITY_NAME