From c6b059493533df9b3f23c03f8d70072a269a1fa7 Mon Sep 17 00:00:00 2001 From: Mircea Nistor Date: Tue, 31 Aug 2021 17:21:14 +0200 Subject: [PATCH] style: remove scar tissue and unused code --- .../src/migrations/SecretBox1588075773000.ts | 33 ------------------- packages/cli/src/migrations/index.ts | 3 -- packages/data-store/src/entities/key.ts | 3 -- .../data-store/src/identifier/did-store.ts | 1 - .../data-store/src/identifier/key-store.ts | 7 ---- .../kms-local/src/key-management-system.ts | 10 +++--- 6 files changed, 5 insertions(+), 52 deletions(-) delete mode 100644 packages/cli/src/migrations/SecretBox1588075773000.ts delete mode 100644 packages/cli/src/migrations/index.ts diff --git a/packages/cli/src/migrations/SecretBox1588075773000.ts b/packages/cli/src/migrations/SecretBox1588075773000.ts deleted file mode 100644 index 7693cb4b2..000000000 --- a/packages/cli/src/migrations/SecretBox1588075773000.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm' -import { Key } from '@veramo/data-store' -import { SecretBox } from '@veramo/kms-local' - -export class SecretBox1588075773000 implements MigrationInterface { - async up(queryRunner: QueryRunner): Promise { - const exists = await queryRunner.hasTable('key') - if (exists && process.env.VERAMO_SECRET_KEY) { - const secretBox = new SecretBox(process.env.VERAMO_SECRET_KEY) - const keys = await queryRunner.connection.getRepository(Key).find() - for (const key of keys) { - if ((key).privateKeyHex) { - (key).privateKeyHex = await secretBox.encrypt((key).privateKeyHex) - } - await key.save() - } - } - } - - async down(queryRunner: QueryRunner): Promise { - const exists = await queryRunner.hasTable('key') - if (exists && process.env.VERAMO_SECRET_KEY) { - const secretBox = new SecretBox(process.env.VERAMO_SECRET_KEY) - const keys = await queryRunner.connection.getRepository(Key).find() - for (const key of keys) { - if ((key).privateKeyHex) { - (key).privateKeyHex = await secretBox.decrypt((key).privateKeyHex) - } - await key.save() - } - } - } -} diff --git a/packages/cli/src/migrations/index.ts b/packages/cli/src/migrations/index.ts deleted file mode 100644 index bfb6f1d92..000000000 --- a/packages/cli/src/migrations/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { SecretBox1588075773000 } from './SecretBox1588075773000' - -export const migrations = [SecretBox1588075773000] diff --git a/packages/data-store/src/entities/key.ts b/packages/data-store/src/entities/key.ts index 076d91b35..ea794e6bb 100644 --- a/packages/data-store/src/entities/key.ts +++ b/packages/data-store/src/entities/key.ts @@ -22,9 +22,6 @@ export class Key extends BaseEntity { //@ts-ignore publicKeyHex: string - // @Column({ nullable: true }) - // privateKeyHex?: string - @Column({ type: 'simple-json', nullable: true, diff --git a/packages/data-store/src/identifier/did-store.ts b/packages/data-store/src/identifier/did-store.ts index e8713555b..dbb2da5bc 100644 --- a/packages/data-store/src/identifier/did-store.ts +++ b/packages/data-store/src/identifier/did-store.ts @@ -112,7 +112,6 @@ export class DIDStore extends AbstractDIDStore { const key = new Key() key.kid = argsKey.kid key.publicKeyHex = argsKey.publicKeyHex - // key.privateKeyHex = argsKey.privateKeyHex key.kms = argsKey.kms key.meta = argsKey.meta identifier.keys.push(key) diff --git a/packages/data-store/src/identifier/key-store.ts b/packages/data-store/src/identifier/key-store.ts index 05ce3779e..f1d3ff4d9 100644 --- a/packages/data-store/src/identifier/key-store.ts +++ b/packages/data-store/src/identifier/key-store.ts @@ -15,9 +15,6 @@ export class KeyStore extends AbstractKeyStore { async get({ kid }: { kid: string }): Promise { const key = await (await this.dbConnection).getRepository(Key).findOne(kid) if (!key) throw Error('Key not found') - // if (this.secretBox && key.privateKeyHex) { - // key.privateKeyHex = await this.secretBox.decrypt(key.privateKeyHex) - // } return key as IKey } @@ -32,10 +29,6 @@ export class KeyStore extends AbstractKeyStore { async import(args: IKey) { const key = new Key() key.kid = args.kid - // key.privateKeyHex = args.privateKeyHex - // if (this.secretBox && key.privateKeyHex) { - // key.privateKeyHex = await this.secretBox.encrypt(key.privateKeyHex) - // } key.publicKeyHex = args.publicKeyHex key.type = args.type key.kms = args.kms diff --git a/packages/kms-local/src/key-management-system.ts b/packages/kms-local/src/key-management-system.ts index 81c6366d5..70be169da 100644 --- a/packages/kms-local/src/key-management-system.ts +++ b/packages/kms-local/src/key-management-system.ts @@ -191,7 +191,7 @@ export class KeyManagementSystem extends AbstractKeyManagementSystem { const wallet = new Wallet(privateKeyHex) const signature = await wallet._signTypedData(msgDomain, msgTypes, msg) - //HEX encoded string + // HEX encoded string return signature } @@ -201,7 +201,7 @@ export class KeyManagementSystem extends AbstractKeyManagementSystem { private async eth_signMessage(privateKeyHex: string, rawMessageBytes: Uint8Array) { const wallet = new Wallet(privateKeyHex) const signature = await wallet.signMessage(rawMessageBytes) - //HEX encoded string, 0x prefixed + // HEX encoded string, 0x prefixed return signature } @@ -220,7 +220,7 @@ export class KeyManagementSystem extends AbstractKeyManagementSystem { } } const signedRawTransaction = await wallet.signTransaction(tx) - //HEX encoded string, 0x prefixed + // HEX encoded string, 0x prefixed return signedRawTransaction } @@ -230,7 +230,7 @@ export class KeyManagementSystem extends AbstractKeyManagementSystem { private async signEdDSA(key: string, data: Uint8Array): Promise { const signer = EdDSASigner(key) const signature = await signer(data) - //base64url encoded string + // base64url encoded string return signature as string } @@ -244,7 +244,7 @@ export class KeyManagementSystem extends AbstractKeyManagementSystem { ): Promise { const signer = ES256KSigner(privateKeyHex, alg === 'ES256K-R') const signature = await signer(data) - //base64url encoded string + // base64url encoded string return signature as string }