From 8269ff43e49b8415f3327589d8d89d8ad80bd5ea Mon Sep 17 00:00:00 2001 From: bhavanakarwade Date: Wed, 26 Jun 2024 19:36:52 +0530 Subject: [PATCH 1/2] wip: applied validations for network type Signed-off-by: bhavanakarwade --- src/controllers/did/DidController.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/controllers/did/DidController.ts b/src/controllers/did/DidController.ts index a4829722..577bd1d8 100644 --- a/src/controllers/did/DidController.ts +++ b/src/controllers/did/DidController.ts @@ -402,7 +402,13 @@ export class DidController extends Controller { public async handlePolygon(createDidOptions: DidCreate) { // need to discuss try catch logic const { endpoint, network, privatekey } = createDidOptions + + if (!network) { + throw new BadRequestError('Network is required for Polygon method') + } + const networkName = network?.split(':')[1] + if (networkName !== 'mainnet' && networkName !== 'testnet') { throw new BadRequestError('Invalid network type') } From 004fb8ed0b6e75b6aac00f64978a622acf7c2aea Mon Sep 17 00:00:00 2001 From: bhavanakarwade Date: Thu, 27 Jun 2024 11:33:29 +0530 Subject: [PATCH 2/2] refactor: added swagger and route file Signed-off-by: bhavanakarwade --- src/routes/routes.ts | 42 ++--- src/routes/swagger.json | 400 ++++++++++------------------------------ 2 files changed, 116 insertions(+), 326 deletions(-) diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 098ab969..8b74f75a 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -50,6 +50,11 @@ const models: TsoaRoute.Models = { "type": {"dataType":"string","validators":{}}, }, // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + "ProofExchangeRecord": { + "dataType": "refAlias", + "type": {"ref":"Record_string.unknown_","validators":{}}, + }, + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa "ProofFormat": { "dataType": "refObject", "properties": { @@ -106,6 +111,17 @@ const models: TsoaRoute.Models = { "additionalProperties": false, }, // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + "PlaintextMessage": { + "dataType": "refObject", + "properties": { + "@type": {"dataType":"string","required":true}, + "@id": {"dataType":"string","required":true}, + "~thread": {"dataType":"nestedObjectLiteral","nestedProperties":{"pthid":{"dataType":"string"},"thid":{"dataType":"string"}}}, + "messageType": {"dataType":"string","required":true}, + }, + "additionalProperties": {"dataType":"any"}, + }, + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa "CreateProofRequestOobOptions": { "dataType": "refObject", "properties": { @@ -124,17 +140,6 @@ const models: TsoaRoute.Models = { "additionalProperties": false, }, // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa - "PlaintextMessage": { - "dataType": "refObject", - "properties": { - "@type": {"dataType":"string","required":true}, - "@id": {"dataType":"string","required":true}, - "~thread": {"dataType":"nestedObjectLiteral","nestedProperties":{"pthid":{"dataType":"string"},"thid":{"dataType":"string"}}}, - "messageType": {"dataType":"string","required":true}, - }, - "additionalProperties": {"dataType":"any"}, - }, - // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa "HandshakeProtocol": { "dataType": "refEnum", "enums": ["https://didcomm.org/didexchange/1.x","https://didcomm.org/connections/1.x"], @@ -1188,8 +1193,6 @@ export function RegisterRoutes(app: Router) { async function ProofController_getProofById(request: ExRequest, response: ExResponse, next: any) { const args: Record = { proofRecordId: {"in":"path","name":"proofRecordId","required":true,"ref":"RecordId"}, - notFoundError: {"in":"res","name":"404","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"reason":{"dataType":"string","required":true}}}, - internalServerError: {"in":"res","name":"500","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"message":{"dataType":"string","required":true}}}, }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa @@ -1226,8 +1229,6 @@ export function RegisterRoutes(app: Router) { async function ProofController_proposeProof(request: ExRequest, response: ExResponse, next: any) { const args: Record = { requestProofProposalOptions: {"in":"body","name":"requestProofProposalOptions","required":true,"ref":"RequestProofProposalOptions"}, - notFoundError: {"in":"res","name":"404","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"reason":{"dataType":"string","required":true}}}, - internalServerError: {"in":"res","name":"500","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"message":{"dataType":"string","required":true}}}, }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa @@ -1264,8 +1265,6 @@ export function RegisterRoutes(app: Router) { async function ProofController_acceptProposal(request: ExRequest, response: ExResponse, next: any) { const args: Record = { acceptProposal: {"in":"body","name":"acceptProposal","required":true,"ref":"AcceptProofProposal"}, - notFoundError: {"in":"res","name":"404","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"reason":{"dataType":"string","required":true}}}, - internalServerError: {"in":"res","name":"500","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"message":{"dataType":"string","required":true}}}, }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa @@ -1302,8 +1301,6 @@ export function RegisterRoutes(app: Router) { async function ProofController_requestProof(request: ExRequest, response: ExResponse, next: any) { const args: Record = { requestProofOptions: {"in":"body","name":"requestProofOptions","required":true,"ref":"RequestProofOptions"}, - notFoundError: {"in":"res","name":"404","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"reason":{"dataType":"string","required":true}}}, - internalServerError: {"in":"res","name":"500","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"message":{"dataType":"string","required":true}}}, }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa @@ -1340,7 +1337,6 @@ export function RegisterRoutes(app: Router) { async function ProofController_createRequest(request: ExRequest, response: ExResponse, next: any) { const args: Record = { createRequestOptions: {"in":"body","name":"createRequestOptions","required":true,"ref":"CreateProofRequestOobOptions"}, - internalServerError: {"in":"res","name":"500","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"message":{"dataType":"string","required":true}}}, }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa @@ -1378,8 +1374,6 @@ export function RegisterRoutes(app: Router) { const args: Record = { proofRecordId: {"in":"path","name":"proofRecordId","required":true,"dataType":"string"}, request: {"in":"body","name":"request","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"comment":{"dataType":"string"},"filterByNonRevocationRequirements":{"dataType":"boolean"},"filterByPresentationPreview":{"dataType":"boolean"}}}, - notFoundError: {"in":"res","name":"404","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"reason":{"dataType":"string","required":true}}}, - internalServerError: {"in":"res","name":"500","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"message":{"dataType":"string","required":true}}}, }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa @@ -1416,8 +1410,6 @@ export function RegisterRoutes(app: Router) { async function ProofController_acceptPresentation(request: ExRequest, response: ExResponse, next: any) { const args: Record = { proofRecordId: {"in":"path","name":"proofRecordId","required":true,"dataType":"string"}, - notFoundError: {"in":"res","name":"404","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"reason":{"dataType":"string","required":true}}}, - internalServerError: {"in":"res","name":"500","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"message":{"dataType":"string","required":true}}}, }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa @@ -1454,8 +1446,6 @@ export function RegisterRoutes(app: Router) { async function ProofController_proofFormData(request: ExRequest, response: ExResponse, next: any) { const args: Record = { proofRecordId: {"in":"path","name":"proofRecordId","required":true,"dataType":"string"}, - notFoundError: {"in":"res","name":"404","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"reason":{"dataType":"string","required":true}}}, - internalServerError: {"in":"res","name":"500","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"message":{"dataType":"string","required":true}}}, }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa diff --git a/src/routes/swagger.json b/src/routes/swagger.json index 7dcdff77..7e0ce458 100644 --- a/src/routes/swagger.json +++ b/src/routes/swagger.json @@ -16,6 +16,9 @@ "type": "string", "example": "821f9b26-ad04-4f56-89b6-e2ef9c72b36e" }, + "ProofExchangeRecord": { + "$ref": "#/components/schemas/Record_string.unknown_" + }, "ProofFormat": { "properties": { "formatKey": { @@ -220,6 +223,37 @@ "type": "object", "additionalProperties": false }, + "PlaintextMessage": { + "properties": { + "@type": { + "type": "string" + }, + "@id": { + "type": "string" + }, + "~thread": { + "properties": { + "pthid": { + "type": "string" + }, + "thid": { + "type": "string" + } + }, + "type": "object" + }, + "messageType": { + "type": "string" + } + }, + "required": [ + "@type", + "@id", + "messageType" + ], + "type": "object", + "additionalProperties": {} + }, "CreateProofRequestOobOptions": { "properties": { "protocolVersion": { @@ -261,37 +295,6 @@ "type": "object", "additionalProperties": false }, - "PlaintextMessage": { - "properties": { - "@type": { - "type": "string" - }, - "@id": { - "type": "string" - }, - "~thread": { - "properties": { - "pthid": { - "type": "string" - }, - "thid": { - "type": "string" - } - }, - "type": "object" - }, - "messageType": { - "type": "string" - } - }, - "required": [ - "@type", - "@id", - "messageType" - ], - "type": "object", - "additionalProperties": {} - }, "HandshakeProtocol": { "description": "Enum values should be sorted based on order of preference. Values will be\nincluded in this order when creating out of band invitations.", "enum": [ @@ -2695,7 +2698,9 @@ "description": "ProofRecord", "content": { "application/json": { - "schema": {}, + "schema": { + "$ref": "#/components/schemas/Record_string.unknown_" + }, "examples": { "Example 1": { "value": { @@ -2710,42 +2715,6 @@ } } } - }, - "404": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "reason": { - "type": "string" - } - }, - "required": [ - "reason" - ], - "type": "object" - } - } - } - }, - "500": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string" - } - }, - "required": [ - "message" - ], - "type": "object" - } - } - } } }, "description": "Retrieve proof record by proof record id", @@ -2777,7 +2746,9 @@ "description": "ProofRecord", "content": { "application/json": { - "schema": {}, + "schema": { + "$ref": "#/components/schemas/ProofExchangeRecord" + }, "examples": { "Example 1": { "value": { @@ -2792,42 +2763,6 @@ } } } - }, - "404": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "reason": { - "type": "string" - } - }, - "required": [ - "reason" - ], - "type": "object" - } - } - } - }, - "500": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string" - } - }, - "required": [ - "message" - ], - "type": "object" - } - } - } } }, "description": "Initiate a new presentation exchange as prover by sending a presentation proposal request\nto the connection with the specified connection id.", @@ -2860,7 +2795,9 @@ "description": "ProofRecord", "content": { "application/json": { - "schema": {}, + "schema": { + "$ref": "#/components/schemas/ProofExchangeRecord" + }, "examples": { "Example 1": { "value": { @@ -2875,42 +2812,6 @@ } } } - }, - "404": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "reason": { - "type": "string" - } - }, - "required": [ - "reason" - ], - "type": "object" - } - } - } - }, - "500": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string" - } - }, - "required": [ - "message" - ], - "type": "object" - } - } - } } }, "description": "Accept a presentation proposal as verifier by sending an accept proposal message\nto the connection associated with the proof record.", @@ -2943,7 +2844,9 @@ "description": "Ok", "content": { "application/json": { - "schema": {}, + "schema": { + "$ref": "#/components/schemas/ProofExchangeRecord" + }, "examples": { "Example 1": { "value": { @@ -2958,44 +2861,9 @@ } } } - }, - "404": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "reason": { - "type": "string" - } - }, - "required": [ - "reason" - ], - "type": "object" - } - } - } - }, - "500": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string" - } - }, - "required": [ - "message" - ], - "type": "object" - } - } - } } }, + "description": "Creates a presentation request bound to existing connection", "tags": [ "Proofs" ], @@ -3023,31 +2891,66 @@ "responses": { "200": { "description": "Ok", - "content": { - "application/json": { - "schema": {} - } - } - }, - "500": { - "description": "", "content": { "application/json": { "schema": { "properties": { - "message": { + "recipientKey": { + "anyOf": [ + { + "properties": { + "recipientKey": {} + }, + "type": "object" + }, + { + "properties": { + "recipientKey": { + "type": "string" + } + }, + "required": [ + "recipientKey" + ], + "type": "object" + } + ] + }, + "outOfBandRecord": { + "$ref": "#/components/schemas/Record_string.unknown_" + }, + "invitation": { + "$ref": "#/components/schemas/PlaintextMessage" + }, + "invitationUrl": { "type": "string" } }, "required": [ - "message" + "recipientKey", + "outOfBandRecord", + "invitation", + "invitationUrl" ], "type": "object" + }, + "examples": { + "Example 1": { + "value": { + "metadata": {}, + "id": "821f9b26-ad04-4f56-89b6-e2ef9c72b36e", + "createdAt": "2022-01-01T00:00:00.000Z", + "connectionId": "2aecf74c-3073-4f98-9acb-92415d096834", + "threadId": "0019d466-5eea-4269-8c40-031b4896c5b7", + "protocolVersion": "v1" + } + } } } } } }, + "description": "Creates a presentation request not bound to any proposal or existing connection", "tags": [ "Proofs" ], @@ -3077,7 +2980,9 @@ "description": "ProofRecord", "content": { "application/json": { - "schema": {}, + "schema": { + "$ref": "#/components/schemas/Record_string.unknown_" + }, "examples": { "Example 1": { "value": { @@ -3092,42 +2997,6 @@ } } } - }, - "404": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "reason": { - "type": "string" - } - }, - "required": [ - "reason" - ], - "type": "object" - } - } - } - }, - "500": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string" - } - }, - "required": [ - "message" - ], - "type": "object" - } - } - } } }, "description": "Accept a presentation request as prover by sending an accept request message\nto the connection associated with the proof record.", @@ -3180,7 +3049,9 @@ "description": "ProofRecord", "content": { "application/json": { - "schema": {}, + "schema": { + "$ref": "#/components/schemas/ProofExchangeRecord" + }, "examples": { "Example 1": { "value": { @@ -3195,42 +3066,6 @@ } } } - }, - "404": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "reason": { - "type": "string" - } - }, - "required": [ - "reason" - ], - "type": "object" - } - } - } - }, - "500": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string" - } - }, - "required": [ - "message" - ], - "type": "object" - } - } - } } }, "description": "Accept a presentation as prover by sending an accept presentation message\nto the connection associated with the proof record.", @@ -3259,7 +3094,7 @@ "operationId": "ProofFormData", "responses": { "200": { - "description": "Ok", + "description": "ProofRecord", "content": { "application/json": { "schema": {}, @@ -3277,44 +3112,9 @@ } } } - }, - "404": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "reason": { - "type": "string" - } - }, - "required": [ - "reason" - ], - "type": "object" - } - } - } - }, - "500": { - "description": "", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string" - } - }, - "required": [ - "message" - ], - "type": "object" - } - } - } } }, + "description": "Return proofRecord", "tags": [ "Proofs" ],