From 2b092e99d1c4f8b7609257a990b76754c6e351ca Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Thu, 24 Sep 2020 15:58:54 +0300 Subject: [PATCH] feat: GraphQL KeyManager --- .../daf-graphql/src/methods/key-manager.ts | 72 +++++++++++++++++-- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/packages/daf-graphql/src/methods/key-manager.ts b/packages/daf-graphql/src/methods/key-manager.ts index c23410286..52ad0af19 100644 --- a/packages/daf-graphql/src/methods/key-manager.ts +++ b/packages/daf-graphql/src/methods/key-manager.ts @@ -9,7 +9,7 @@ export const keyManagerGetKeyManagementSystems: IAgentGraphQLMethod = { `, typeDef: ` extend type Query { - keyManagerGetKeyManagementSystems: [String] + keyManagerGetKeyManagementSystems: [String!] } `, } @@ -17,7 +17,7 @@ export const keyManagerGetKeyManagementSystems: IAgentGraphQLMethod = { export const keyManagerGetKey: IAgentGraphQLMethod = { type: 'Query', query: ` - query keyManagerGetKey($kid: String) { + query keyManagerGetKey($kid: String!) { keyManagerGetKey(kid: $kid) { kid kms @@ -30,7 +30,7 @@ export const keyManagerGetKey: IAgentGraphQLMethod = { `, typeDef: ` extend type Query { - keyManagerGetKey(kid: String): Key + keyManagerGetKey(kid: String!): Key } `, } @@ -38,7 +38,7 @@ export const keyManagerGetKey: IAgentGraphQLMethod = { export const keyManagerCreateKey: IAgentGraphQLMethod = { type: 'Mutation', query: ` - mutation keyManagerCreateKey($type: String, $kms: String, $meta: KeyMetaInput) { + mutation keyManagerCreateKey($type: String!, $kms: String!, $meta: KeyMetaInput) { keyManagerCreateKey(type: $type, kms: $kms, meta: $meta) { kid kms @@ -51,7 +51,65 @@ export const keyManagerCreateKey: IAgentGraphQLMethod = { typeDef: ` scalar KeyMetaInput extend type Mutation { - keyManagerCreateKey(type: String, kms: String, meta: KeyMetaInput): Key! + keyManagerCreateKey(type: String!, kms: String!, meta: KeyMetaInput): Key! + } + `, +} + +export const keyManagerDeleteKey: IAgentGraphQLMethod = { + type: 'Mutation', + query: ` + mutation keyManagerDeleteKey($kid: String!) { + keyManagerDeleteKey(kid: $kid) + } + `, + typeDef: ` + extend type Mutation { + keyManagerDeleteKey(kid: String!): Boolean! + } + `, +} + +export const keyManagerImportKey: IAgentGraphQLMethod = { + type: 'Mutation', + query: ` + mutation keyManagerImportKey($kid: String!, $type: String!, $kms: String!, $publicKeyHex: String!, $privateKeyHex: String, $meta: KeyMetaInput) { + keyManagerImportKey(kid: $kid, type: $type, kms: $kms, publicKeyHex: $publicKeyHex, privateKeyHex: $privateKeyHex, meta: $meta) + } + `, + typeDef: ` + extend type Mutation { + keyManagerImportKey(kid: String!, type: String!, kms: String!, publicKeyHex: String!, privateKeyHex: String, meta: KeyMetaInput): Boolean! + } + `, +} + +export const keyManagerSignJWT: IAgentGraphQLMethod = { + type: 'Mutation', + query: ` + mutation keyManagerSignJWT($kid: String!, $data: String!) { + keyManagerSignJWT(kid: $kid, data: $data) + } + `, + typeDef: ` + scalar JWTSignature + extend type Mutation { + keyManagerSignJWT(kid: String!, data: String!): JWTSignature! + } + `, +} + +export const keyManagerSignEthTX: IAgentGraphQLMethod = { + type: 'Mutation', + query: ` + mutation keyManagerSignEthTX($kid: String!, $transaction: TransactionInput!) { + keyManagerSignEthTX(kid: $kid, transaction: $transaction) + } + `, + typeDef: ` + scalar TransactionInput + extend type Mutation { + keyManagerSignEthTX(kid: String!, transaction: TransactionInput!): String! } `, } @@ -60,6 +118,10 @@ export const supportedMethods: Record = { keyManagerGetKeyManagementSystems, keyManagerCreateKey, keyManagerGetKey, + keyManagerDeleteKey, + keyManagerImportKey, + keyManagerSignJWT, + keyManagerSignEthTX, } export default supportedMethods