Skip to content

Commit

Permalink
chore: Prepare validation part for moving out to make it reusable [DE…
Browse files Browse the repository at this point in the history
…V-3493] (#453)

* Move types to validation and types refact

* Fix build

---------

Co-authored-by: DaevMithran <daevmithran1999@gmail.com>
Co-authored-by: DaevMithran <61043607+DaevMithran@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 5, 2024
1 parent d3b385f commit 8f1bd8f
Show file tree
Hide file tree
Showing 24 changed files with 396 additions and 423 deletions.
34 changes: 19 additions & 15 deletions src/controllers/credential-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ import { check, validationResult, query } from './validator/index.js';
import { fromString } from 'uint8arrays';
import { StatusCodes } from 'http-status-codes';
import { IdentityServiceStrategySetup } from '../services/identity/index.js';
import type {
ITrackOperation,
} from '../types/shared.js';
import type { CheckStatusListSuccessfulResponseBody, FeePaymentOptions } from '../types/credential-status.js';
import {
DefaultStatusAction,
DefaultStatusActionPurposeMap,
DefaultStatusActions, MinimalPaymentCondition
} from '../types/credential-status.js';
import type {
SearchStatusListQuery,
SearchStatusListSuccessfulResponseBody,
SearchStatusListUnsuccessfulResponseBody
} from '../types/credential-status.js';
import type {
CheckStatusListRequestBody,
CheckStatusListRequestQuery,
CheckStatusListUnsuccessfulResponseBody,
Expand All @@ -14,24 +28,14 @@ import {
CreateUnencryptedStatusListRequestBody,
CreateUnencryptedStatusListRequestQuery,
CreateUnencryptedStatusListSuccessfulResponseBody,
CreateUnencryptedStatusListUnsuccessfulResponseBody,
DefaultStatusAction,
DefaultStatusActionPurposeMap,
DefaultStatusActions,
FeePaymentOptions,
ITrackOperation,
MinimalPaymentCondition,
SearchStatusListQuery,
SearchStatusListSuccessfulResponseBody,
SearchStatusListUnsuccessfulResponseBody,
UpdateEncryptedStatusListRequestBody,
CreateUnencryptedStatusListUnsuccessfulResponseBody, UpdateEncryptedStatusListRequestBody,
UpdateEncryptedStatusListSuccessfulResponseBody,
UpdateEncryptedStatusListUnsuccessfulResponseBody,
UpdateUnencryptedStatusListRequestBody,
UpdateUnencryptedStatusListRequestQuery,
UpdateUnencryptedStatusListSuccessfulResponseBody,
UpdateUnencryptedStatusListUnsuccessfulResponseBody,
} from '../types/shared.js';
UpdateUnencryptedStatusListUnsuccessfulResponseBody
} from '../types/credential-status.js';
import {
BulkRevocationResult,
BulkSuspensionResult,
Expand Down Expand Up @@ -1209,11 +1213,11 @@ export class CredentialStatusController {

// handle error
if (result.error) {
return response.status(StatusCodes.BAD_REQUEST).json(result);
return response.status(StatusCodes.BAD_REQUEST).json(result as CheckStatusListUnsuccessfulResponseBody);
}

// return result
return response.status(StatusCodes.OK).json(result);
return response.status(StatusCodes.OK).json(result as CheckStatusListSuccessfulResponseBody);
} catch (error) {
// define error
const errorRef = error as Record<string, unknown>;
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { IdentityServiceStrategySetup } from '../services/identity/index.js';
import { decryptPrivateKey, generateDidDoc, getQueryParams } from '../helpers/helpers.js';
import { bases } from 'multiformats/basics';
import { base64ToBytes } from 'did-jwt';
import type { CreateDidRequestBody, KeyImportRequest } from '../types/shared.js';
import type { CreateDidRequestBody, KeyImportRequest } from '../types/did.js';

import { check, validationResult, param } from './validator/index.js';
import type { IKey, RequireOnly } from '@veramo/core';
import { extractPublicKeyHex } from '@veramo/utils';
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StatusCodes } from 'http-status-codes';
import { check, validationResult, query } from './validator/index.js';
import { IdentityServiceStrategySetup } from '../services/identity/index.js';
import { CheqdW3CVerifiablePresentation } from '../services/w3c-presentation.js';
import type { VerifyPresentationResponseBody } from '../types/shared.js';
import type { VerifyPresentationResponseBody } from '../types/presentation.js';
import { isIssuerDidDeactivated } from '../services/helpers.js';

export class PresentationController {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/validator/credential-status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CheqdCredentialStatus } from '../../types/shared.js';
import type { CheqdCredentialStatus } from '../../types/validation.js';
import type { IValidationResult, IValidator } from './validator.js';

export class CredentialStatusValidator implements IValidator {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/validator/credential.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CheqdW3CVerifiableCredential, ICheqdCredential } from '../../services/w3c-credential.js';
import type { CheqdCredentialStatus } from '../../types/shared.js';
import type { CheqdCredentialStatus } from '../../types/validation.js';
import { CredentialStatusValidator } from './credential-status.js';
import { CheqdDIDValidator, KeyDIDValidator } from './did.js';
import { JsonLDProofValidator } from './jsonld-proof.js';
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Validatable } from './validator.js';
import type { Service, VerificationMethod } from 'did-resolver';
import { VerificationMethodValidator } from './verification-method.js';
import { CreateDIDDocumentServiceValidator } from './service-create-request.js';
import type { CreateDIDService } from '../../types/shared.js';
import type { CreateDIDService } from '../../types/validation.js';
import { ServiceValidator } from './service.js';
import { DIDArrayValidator } from './did-array.js';
import { CheqdDidLinkedAlsoKnownAsValidator } from './resource-also-known-as.js';
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/validator/jsonld-proof.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JSONLD_PROOF_TYPES } from '../../types/constants.js';
import type { JSONLDProofType } from '../../types/shared.js';
import type { JSONLDProofType } from '../../types/validation.js';
import type { IValidationResult, IValidator, Validatable } from './validator.js';

export class JsonLDProofValidator implements IValidator {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/validator/jwt-proof.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InvalidTokenError, jwtDecode } from 'jwt-decode';
import { JWT_PROOF_TYPE } from '../../types/constants.js';
import type { JwtProof2020 } from '../../types/shared.js';
import type { JwtProof2020 } from '../../types/validation.js';
import type { IValidationResult, IValidator, Validatable } from './validator.js';

export class JWTProofValidator implements IValidator {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/validator/service-create-request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IValidationResult, IValidator, Validatable } from './validator.js';
import { Helpers, type IHelpers } from './helpers.js';
import type { CreateDIDService } from '../../types/shared.js';
import type { CreateDIDService } from '../../types/validation.js';

// It's a special validator for the service create request. It's not a part of the DID Document
export class CreateDIDDocumentServiceValidator implements IValidator {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/validator/validator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { W3CVerifiableCredential, W3CVerifiablePresentation } from '@veramo/core';
import type { DIDDocument, VerificationMethod, Service } from 'did-resolver';
import type { IHelpers } from './helpers.js';
import type { CreateDIDService, JwtProof2020, CheqdCredentialStatus, JSONLDProofType } from '../../types/shared.js';
import type { CreateDIDService, JwtProof2020, JSONLDProofType, CheqdCredentialStatus } from '../../types/validation.js';
import type { ICheqdCredential } from '../../services/w3c-credential.js';
import type { ICheqdPresentation } from '../../services/w3c-presentation.js';
import type { AlternativeUri } from '@cheqd/ts-proto/cheqd/resource/v2/resource.js';
Expand Down
2 changes: 1 addition & 1 deletion src/services/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CredentialPayload, VerifiableCredential } from '@veramo/core';

import { VC_CONTEXT, VC_TYPE } from '../types/constants.js';
import type { CredentialRequest } from '../types/shared.js';
import type { CredentialRequest } from '../types/credential.js';
import { IdentityServiceStrategySetup } from './identity/index.js';
import { v4 } from 'uuid';
import * as dotenv from 'dotenv';
Expand Down
20 changes: 10 additions & 10 deletions src/services/identity/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ import type {
TransactionResult,
} from '@cheqd/did-provider-cheqd';
import type {
BroadcastStatusListOptions,
CheckStatusListOptions,
CreateEncryptedStatusListOptions,
CreateUnencryptedStatusListOptions,
CredentialRequest,
FeePaymentOptions,
ITrackOperation,
StatusOptions,
ITrackResult,
UpdateEncryptedStatusListOptions,
UpdateUnencryptedStatusListOptions,
VeramoAgent,
VerificationOptions,
} from '../../types/shared';
import type { VerificationOptions } from '../../types/credential';
import type { FeePaymentOptions } from '../../types/credential-status';
import type { CredentialRequest } from '../../types/credential';
import type { CheckStatusListOptions } from '../../types/credential-status';
import type { StatusOptions } from '../../types/credential-status';
import type {
BroadcastStatusListOptions, CreateEncryptedStatusListOptions,
CreateUnencryptedStatusListOptions, UpdateEncryptedStatusListOptions,
UpdateUnencryptedStatusListOptions
} from '../../types/credential-status';
import type { IIdentityService } from './index.js';
import type { CustomerEntity } from '../../database/entities/customer.entity.js';
import type { KeyEntity } from '../../database/entities/key.entity.js';
Expand Down
28 changes: 14 additions & 14 deletions src/services/identity/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ import type { CheqdNetwork } from '@cheqd/sdk';
import { getDidKeyResolver as KeyDidResolver } from '@veramo/did-provider-key';
import { Resolver, ResolverRegistry } from 'did-resolver';
import {
BroadcastStatusListOptions,
CheckStatusListOptions,
DefaultDidUrlPattern,
CreateAgentRequest,
CreateUnencryptedStatusListOptions,
CredentialRequest,
RevocationStatusOptions,
StatusOptions,
SuspensionStatusOptions,
UpdateUnencryptedStatusListOptions,
VeramoAgent,
VerificationOptions,
CreateEncryptedStatusListOptions,
DefaultStatusActions,
UpdateEncryptedStatusListOptions,
SearchStatusListResult,
FeePaymentOptions,
} from '../../types/shared.js';
import type { VerificationOptions } from '../../types/credential.js';
import type { FeePaymentOptions } from '../../types/credential-status.js';
import type { CredentialRequest } from '../../types/credential.js';
import { DefaultStatusActions } from '../../types/credential-status.js';
import type { CheckStatusListOptions } from '../../types/credential-status.js';
import type {
RevocationStatusOptions,
StatusOptions,
SuspensionStatusOptions
} from '../../types/credential-status.js';
import type {
BroadcastStatusListOptions, CreateUnencryptedStatusListOptions, UpdateUnencryptedStatusListOptions, CreateEncryptedStatusListOptions, UpdateEncryptedStatusListOptions,
SearchStatusListResult
} from '../../types/credential-status.js';
import { MINIMAL_DENOM, VC_PROOF_FORMAT, VC_REMOVE_ORIGINAL_FIELDS } from '../../types/constants.js';
import { toCoin, toDefaultDkg, toMinimalDenom } from '../../helpers/helpers.js';
import { jwtDecode } from 'jwt-decode';
Expand Down
10 changes: 4 additions & 6 deletions src/services/identity/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
import type { DIDResolutionResult } from 'did-resolver';
import { AbstractIdentityService } from './abstract.js';
import type { IVerifyResult, VerifiableCredential, VerifiablePresentation } from '@veramo/core';
import type {
CheckStatusListOptions,
FeePaymentOptions,
SearchStatusListResult,
VerificationOptions,
} from '../../types/shared';
import type { VerificationOptions } from '../../types/credential.js';
import type { FeePaymentOptions } from '../../types/credential-status.js';
import type { CheckStatusListOptions } from '../../types/credential-status.js';
import type { SearchStatusListResult } from '../../types/credential-status.js';
import type { StatusCheckResult, TransactionResult } from '@cheqd/did-provider-cheqd';
import { Veramo } from './agent.js';
import type { CustomerEntity } from '../../database/entities/customer.entity.js';
Expand Down
23 changes: 11 additions & 12 deletions src/services/identity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ import type {
TransactionResult,
} from '@cheqd/did-provider-cheqd';
import type {
BroadcastStatusListOptions,
CheckStatusListOptions,
CreateEncryptedStatusListOptions,
CreateUnencryptedStatusListOptions,
CredentialRequest,
FeePaymentOptions,
ITrackOperation,
SearchStatusListResult,
StatusOptions,
ITrackResult,
UpdateEncryptedStatusListOptions,
UpdateUnencryptedStatusListOptions,
VeramoAgent,
VerificationOptions,
} from '../../types/shared';
} from '../../types/shared.js';
import type { VerificationOptions } from '../../types/credential.js';
import type { FeePaymentOptions } from '../../types/credential-status.js';
import type { CredentialRequest } from '../../types/credential.js';
import type { CheckStatusListOptions } from '../../types/credential-status.js';
import type { StatusOptions } from '../../types/credential-status.js';
import type {
BroadcastStatusListOptions, CreateEncryptedStatusListOptions,
CreateUnencryptedStatusListOptions, SearchStatusListResult, UpdateEncryptedStatusListOptions,
UpdateUnencryptedStatusListOptions
} from '../../types/credential-status.js';
import type { CustomerEntity } from '../../database/entities/customer.entity.js';
import type { KeyEntity } from '../../database/entities/key.entity.js';
import type { UserEntity } from '../../database/entities/user.entity.js';
Expand Down
20 changes: 9 additions & 11 deletions src/services/identity/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ import {
LitNetworks,
} from '@cheqd/did-provider-cheqd';
import { CheqdNetwork } from '@cheqd/sdk';
import type { VerificationOptions } from '../../types/credential.js';
import type { FeePaymentOptions } from '../../types/credential-status.js';
import type { CredentialRequest } from '../../types/credential.js';
import type { CheckStatusListOptions } from '../../types/credential-status.js';
import type { StatusOptions } from '../../types/credential-status.js';
import type {
BroadcastStatusListOptions,
CheckStatusListOptions,
CreateEncryptedStatusListOptions,
CreateUnencryptedStatusListOptions,
CredentialRequest,
FeePaymentOptions,
StatusOptions,
UpdateEncryptedStatusListOptions,
UpdateUnencryptedStatusListOptions,
VerificationOptions,
} from '../../types/shared.js';
BroadcastStatusListOptions, CreateEncryptedStatusListOptions,
CreateUnencryptedStatusListOptions, UpdateEncryptedStatusListOptions,
UpdateUnencryptedStatusListOptions
} from '../../types/credential-status.js';
import { DefaultIdentityService } from './default.js';
import { Connection } from '../../database/connection/connection.js';
import { Veramo } from './agent.js';
Expand Down
16 changes: 6 additions & 10 deletions src/services/identity/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,17 @@ import {
type TransactionResult,
} from '@cheqd/did-provider-cheqd';
import {
BroadcastStatusListOptions,
CheckStatusListOptions,
DefaultDidUrlPattern,
CreateUnencryptedStatusListOptions,
CredentialRequest,
StatusOptions,
UpdateUnencryptedStatusListOptions,
VeramoAgent,
VerificationOptions,
CreateEncryptedStatusListOptions,
FeePaymentOptions,
UpdateEncryptedStatusListOptions,
ITrackResult,
ITrackOperation,
} from '../../types/shared.js';
import type { VerificationOptions } from '../../types/credential.js';
import type { FeePaymentOptions } from '../../types/credential-status.js';
import type { CredentialRequest } from '../../types/credential.js';
import type { CheckStatusListOptions } from '../../types/credential-status.js';
import type { StatusOptions } from '../../types/credential-status.js';
import type { BroadcastStatusListOptions, CreateUnencryptedStatusListOptions, UpdateUnencryptedStatusListOptions, CreateEncryptedStatusListOptions, UpdateEncryptedStatusListOptions } from '../../types/credential-status.js';
import { Connection } from '../../database/connection/connection.js';
import type { CustomerEntity } from '../../database/entities/customer.entity.js';
import { Veramo } from './agent.js';
Expand Down
3 changes: 2 additions & 1 deletion src/services/w3c-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { JwtPayload, jwtDecode } from 'jwt-decode';
import type { IIdentityService } from './identity/index.js';
import type { CustomerEntity } from '../database/entities/customer.entity.js';
import { toNetwork } from '../helpers/helpers.js';
import { CommonReturn, type FeePaymentOptions } from '../types/shared.js';
import { CommonReturn } from '../types/shared.js';
import type { FeePaymentOptions } from '../types/credential-status.js';
import { JWT_PROOF_TYPE } from '../types/constants.js';
import type { StatusList2021Revocation, StatusList2021Suspension } from '@cheqd/did-provider-cheqd';

Expand Down
Loading

0 comments on commit 8f1bd8f

Please sign in to comment.