Skip to content

Commit

Permalink
Add createdAt adding for key creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Nikitin committed Nov 2, 2023
1 parent c5937ac commit 04e55eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/database/migrations/MigrateData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion src/services/identity/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/services/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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);
}

Expand Down

0 comments on commit 04e55eb

Please sign in to comment.