From 2d56f736641b0692bec00be90b0789affc56e4cc Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:27:07 +0200 Subject: [PATCH 1/5] database migration --- .../0067-private_key_in_community_table.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 database/migrations/0067-private_key_in_community_table.ts diff --git a/database/migrations/0067-private_key_in_community_table.ts b/database/migrations/0067-private_key_in_community_table.ts new file mode 100644 index 000000000..999ef8708 --- /dev/null +++ b/database/migrations/0067-private_key_in_community_table.ts @@ -0,0 +1,16 @@ +/* MIGRATION TO ADD PRIVATE KEY IN COMMUNITY TABLE + * + * This migration adds a field for the private key in the community.table + */ + +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + 'ALTER TABLE `communities` ADD COLUMN `private_key` binary(64) DEFAULT NULL AFTER `public_key`;', + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('ALTER TABLE `communities` DROP COLUMN `private_key`;') +} From 93a67ac35aa260a298e41b8165ffb686f9eac60f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:28:17 +0200 Subject: [PATCH 2/5] require the new database version --- backend/src/config/index.ts | 2 +- dht-node/src/config/index.ts | 2 +- federation/src/config/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 8d1ed8ae6..70830359f 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,7 +12,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0066-x-community-sendcoins-transactions_table', + DB_VERSION: '0067-private_key_in_community_table', DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 43949201b..255a4def0 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -3,7 +3,7 @@ import dotenv from 'dotenv' dotenv.config() const constants = { - DB_VERSION: '0066-x-community-sendcoins-transactions_table', + DB_VERSION: '0067-private_key_in_community_table', LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info LOG_LEVEL: process.env.LOG_LEVEL || 'info', diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index 66d8a056c..0dade2a6a 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ const constants = { - DB_VERSION: '0066-x-community-sendcoins-transactions_table', + DB_VERSION: '0067-private_key_in_community_table', // DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info From a58e698878d77823309a095bef70e0d293c507af Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:31:34 +0200 Subject: [PATCH 3/5] updated Community entity to include private Key field --- .../Community.ts | 63 +++++++++++++++++++ database/entity/Community.ts | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 database/entity/0067-private_key_in_community_table/Community.ts diff --git a/database/entity/0067-private_key_in_community_table/Community.ts b/database/entity/0067-private_key_in_community_table/Community.ts new file mode 100644 index 000000000..dcb55c875 --- /dev/null +++ b/database/entity/0067-private_key_in_community_table/Community.ts @@ -0,0 +1,63 @@ +import { + BaseEntity, + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + UpdateDateColumn, +} from 'typeorm' + +@Entity('communities') +export class Community extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ name: 'foreign', type: 'bool', nullable: false, default: true }) + foreign: boolean + + @Column({ name: 'url', length: 255, nullable: false }) + url: string + + @Column({ name: 'public_key', type: 'binary', length: 64, nullable: false }) + publicKey: Buffer + + @Column({ name: 'private_key', type: 'binary', length: 64, nullable: true }) + privateKey: Buffer | null + + @Column({ + name: 'community_uuid', + type: 'char', + length: 36, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + communityUuid: string | null + + @Column({ name: 'authenticated_at', type: 'datetime', nullable: true }) + authenticatedAt: Date | null + + @Column({ name: 'name', type: 'varchar', length: 40, nullable: true }) + name: string | null + + @Column({ name: 'description', type: 'varchar', length: 255, nullable: true }) + description: string | null + + @CreateDateColumn({ name: 'creation_date', type: 'datetime', nullable: true }) + creationDate: Date | null + + @CreateDateColumn({ + name: 'created_at', + type: 'datetime', + default: () => 'CURRENT_TIMESTAMP(3)', + nullable: false, + }) + createdAt: Date + + @UpdateDateColumn({ + name: 'updated_at', + type: 'datetime', + onUpdate: 'CURRENT_TIMESTAMP(3)', + nullable: true, + }) + updatedAt: Date | null +} diff --git a/database/entity/Community.ts b/database/entity/Community.ts index ee08323b6..5df0f70fe 100644 --- a/database/entity/Community.ts +++ b/database/entity/Community.ts @@ -1 +1 @@ -export { Community } from './0065-refactor_communities_table/Community' +export { Community } from './0067-private_key_in_community_table/Community' From e4f8cd0f35a70f99ac9238099ac65d8bad107daf Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:35:08 +0200 Subject: [PATCH 4/5] save privatekey for home community --- dht-node/src/dht_node/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dht-node/src/dht_node/index.ts b/dht-node/src/dht_node/index.ts index adef0fc52..639909735 100644 --- a/dht-node/src/dht_node/index.ts +++ b/dht-node/src/dht_node/index.ts @@ -220,6 +220,7 @@ async function writeHomeCommunityEntry(keyPair: KeyPair): Promise { if (homeCom) { // simply update the existing entry, but it MUST keep the ID and UUID because of possible relations homeCom.publicKey = keyPair.publicKey + homeCom.privateKey = keyPair.secretKey homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/' homeCom.name = CONFIG.COMMUNITY_NAME homeCom.description = CONFIG.COMMUNITY_DESCRIPTION @@ -230,6 +231,7 @@ async function writeHomeCommunityEntry(keyPair: KeyPair): Promise { homeCom = new DbCommunity() homeCom.foreign = false homeCom.publicKey = keyPair.publicKey + homeCom.privateKey = keyPair.secretKey homeCom.communityUuid = await newCommunityUuid() homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/' homeCom.name = CONFIG.COMMUNITY_NAME From feedab3cebde52cdc6fc18ba744405fa58cdb13f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:47:20 +0200 Subject: [PATCH 5/5] missing new line --- database/migrations/0067-private_key_in_community_table.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/database/migrations/0067-private_key_in_community_table.ts b/database/migrations/0067-private_key_in_community_table.ts index 999ef8708..f36e68b16 100644 --- a/database/migrations/0067-private_key_in_community_table.ts +++ b/database/migrations/0067-private_key_in_community_table.ts @@ -5,6 +5,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ + export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn( 'ALTER TABLE `communities` ADD COLUMN `private_key` binary(64) DEFAULT NULL AFTER `public_key`;',