diff --git a/src/database/migrations/MigrateData.ts b/src/database/migrations/MigrateData.ts index bca5bc2e..69d3d875 100644 --- a/src/database/migrations/MigrateData.ts +++ b/src/database/migrations/MigrateData.ts @@ -143,7 +143,7 @@ export class MigrateData1695740345977 implements MigrationInterface { for (const kid of oldCustomer.kids) { console.info(`Updating key with kid ${kid}`); const _key = await queryRunner.query( - `UPDATE "key" SET "customerId" = '${customerEntity.customerId}' WHERE kid = '${kid}'` + `UPDATE "key" SET "customerId" = '${customerEntity.customerId}', "createdAt" = '${customerEntity.createdAt.toISOString()}' WHERE kid = '${kid}'` ); if (!_key) { throw new Error(`Failed to update key with kid ${kid}`); diff --git a/src/services/identity/postgres.ts b/src/services/identity/postgres.ts index 16908f3a..144ed28f 100644 --- a/src/services/identity/postgres.ts +++ b/src/services/identity/postgres.ts @@ -151,7 +151,7 @@ export class PostgresIdentityService extends DefaultIdentityService { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const key = await Veramo.instance.createKey(this.agent!, type); // Update our specific key columns - return await KeyService.instance.update(key.kid, customer, keyAlias); + return await KeyService.instance.update(key.kid, customer, keyAlias, new Date()); } async getKey(kid: string, customer: CustomerEntity) { diff --git a/src/services/key.ts b/src/services/key.ts index 4cb0d7f2..c4c0b941 100644 --- a/src/services/key.ts +++ b/src/services/key.ts @@ -17,7 +17,7 @@ export class KeyService { this.keyRepository = Connection.instance.dbConnection.getRepository(KeyEntity); } - public async update(kid: string, customer?: CustomerEntity, keyAlias?: string) { + public async update(kid: string, customer?: CustomerEntity, keyAlias?: string, createdAt? : Date) { const existingKey = await this.keyRepository.findOneBy({ kid }); if (!existingKey) { throw new Error(`kid not found`); @@ -28,6 +28,10 @@ export class KeyService { if (keyAlias) { existingKey.publicKeyAlias = keyAlias; } + if (createdAt) { + // It's a workaround cause Veramo creates key inside without createdAt field + existingKey.createdAt = createdAt; + } return await this.keyRepository.save(existingKey); }