From 3e3a6843a77cf389be9aa6414a2f77ebe26adc62 Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Fri, 14 Aug 2020 12:35:31 +0300 Subject: [PATCH] fix: Removing EcdsaSignature type --- .../src/abstract/abstract-key-management-system.ts | 4 ++-- packages/daf-core/src/key-manager.ts | 6 +++--- packages/daf-core/src/types.ts | 7 ------- packages/daf-libsodium/src/key-management-system.ts | 6 +++--- scripts/generate-schemas.ts | 13 ++++++++----- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/packages/daf-core/src/abstract/abstract-key-management-system.ts b/packages/daf-core/src/abstract/abstract-key-management-system.ts index 0179b1466..807842594 100644 --- a/packages/daf-core/src/abstract/abstract-key-management-system.ts +++ b/packages/daf-core/src/abstract/abstract-key-management-system.ts @@ -1,10 +1,10 @@ -import { IKey, EcdsaSignature, TKeyType } from '../types' +import { IKey, TKeyType } from '../types' export abstract class AbstractKeyManagementSystem { abstract createKey(args: { type: TKeyType; meta?: any }): Promise> abstract deleteKey(args: { kid: string }): Promise abstract encryptJWE(args: { key: IKey; to: Omit; data: string }): Promise abstract decryptJWE(args: { key: IKey; data: string }): Promise - abstract signJWT(args: { key: IKey; data: string }): Promise + abstract signJWT(args: { key: IKey; data: string }): Promise abstract signEthTX(args: { key: IKey; transaction: object }): Promise } diff --git a/packages/daf-core/src/key-manager.ts b/packages/daf-core/src/key-manager.ts index 10b3c96f1..87e483b29 100644 --- a/packages/daf-core/src/key-manager.ts +++ b/packages/daf-core/src/key-manager.ts @@ -1,6 +1,6 @@ import { AbstractKeyStore } from './abstract/abstract-key-store' import { AbstractKeyManagementSystem } from './abstract/abstract-key-management-system' -import { IKey, TKeyType, EcdsaSignature, IAgentPlugin, IPluginMethodMap } from './types' +import { IKey, TKeyType, IAgentPlugin, IPluginMethodMap } from './types' export interface IKeyManagerCreateKeyArgs { type: TKeyType @@ -38,7 +38,7 @@ export interface IKeyManager extends IPluginMethodMap { keyManagerImportKey(args: IKey): Promise keyManagerEncryptJWE(args: IKeyManagerEncryptJWEArgs): Promise keyManagerDecryptJWE(args: IKeyManagerDecryptJWEArgs): Promise - keyManagerSignJWT(args: IKeyManagerSignJWTArgs): Promise + keyManagerSignJWT(args: IKeyManagerSignJWTArgs): Promise keyManagerSignEthTX(args: IKeyManagerSignEthTXArgs): Promise } export class KeyManager implements IAgentPlugin { @@ -105,7 +105,7 @@ export class KeyManager implements IAgentPlugin { return kms.decryptJWE({ key, data }) } - async keyManagerSignJWT({ kid, data }: IKeyManagerSignJWTArgs): Promise { + async keyManagerSignJWT({ kid, data }: IKeyManagerSignJWTArgs): Promise { const key = await this.store.get({ kid }) const kms = this.getKms(key.kms) return kms.signJWT({ key, data }) diff --git a/packages/daf-core/src/types.ts b/packages/daf-core/src/types.ts index 9bd97a9ba..5e938391f 100644 --- a/packages/daf-core/src/types.ts +++ b/packages/daf-core/src/types.ts @@ -32,13 +32,6 @@ export interface IIdentity { services: IService[] } -// Todo make it a String -export interface EcdsaSignature { - r: string - s: string - recoveryParam?: number -} - export interface IMetaData { type: string value?: string diff --git a/packages/daf-libsodium/src/key-management-system.ts b/packages/daf-libsodium/src/key-management-system.ts index 38cffdc87..412b071e0 100644 --- a/packages/daf-libsodium/src/key-management-system.ts +++ b/packages/daf-libsodium/src/key-management-system.ts @@ -1,4 +1,4 @@ -import { AbstractKeyManagementSystem, TKeyType, IKey, EcdsaSignature } from 'daf-core' +import { AbstractKeyManagementSystem, TKeyType, IKey } from 'daf-core' import sodium from 'libsodium-wrappers' import { SimpleSigner } from 'did-jwt' const EC = require('elliptic').ec @@ -71,9 +71,9 @@ export class KeyManagementSystem extends AbstractKeyManagementSystem { return sign(transaction, '0x' + key.privateKeyHex) } - async signJWT({ key, data }: { key: IKey; data: string }): Promise { + async signJWT({ key, data }: { key: IKey; data: string }): Promise { if (!key.privateKeyHex) throw Error('No private key for kid: ' + key.kid) const signer = SimpleSigner(key.privateKeyHex) - return signer(data) + return signer(data) as any as string } } diff --git a/scripts/generate-schemas.ts b/scripts/generate-schemas.ts index 815097ae6..8169ab1ff 100644 --- a/scripts/generate-schemas.ts +++ b/scripts/generate-schemas.ts @@ -49,10 +49,8 @@ function createSchema(generator: TJS.JsonSchemaGenerator, symbol: string) { return { components: { schemas: {} } } } - //hack - let fixedSymbol = symbol === 'EcdsaSignature | string' ? 'EcdsaSignature' : symbol - // TODO fix 'EcdsaSignature | string' in openApi responses - fixedSymbol = fixedSymbol.replace('Array<', '').replace('>', '') + + let fixedSymbol = symbol.replace('Array<', '').replace('>', '') const schema = generator.getSchemaForSymbol(fixedSymbol) @@ -104,7 +102,12 @@ function getResponseSchema(response: string): OpenAPIV3.ReferenceObject | OpenAP for (const packageName of Object.keys(agentPlugins)) { const program = TJS.getProgramFromFiles([resolve('packages/' + packageName + '/src/index.ts')]) - const generator = TJS.buildGenerator(program, { required: true, topRef: true, excludePrivate: false }) + const generator = TJS.buildGenerator(program, { + required: true, + topRef: true, + excludePrivate: false, + }) + const apiModel: ApiModel = new ApiModel() const apiPackage = apiModel.loadPackage(