diff --git a/packages/sample-server/package.json b/packages/sample-server/package.json index c425abc..4590d0f 100644 --- a/packages/sample-server/package.json +++ b/packages/sample-server/package.json @@ -17,7 +17,7 @@ "@fastify/autoload": "~5.7.1", "env-var": "~7.3.0", "fastify": "~4.15.0", - "@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.4.0" + "@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.5.0" }, "devDependencies": { "@jest/globals": "~29.5.0", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 47bd5d3..de86fbc 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@velocitycareerlabs/vnf-nodejs-wallet-sdk", - "version": "0.4.0", + "version": "0.5.0", "description": "VNF Wallet SDK Nodejs", "main": "dist/index.js", "types": "dist/global.d.ts", diff --git a/packages/sdk/src/api/VCL.ts b/packages/sdk/src/api/VCL.ts index 35ad9c9..591143c 100644 --- a/packages/sdk/src/api/VCL.ts +++ b/packages/sdk/src/api/VCL.ts @@ -6,13 +6,13 @@ import VCLCredentialTypes from "./entities/VCLCredentialTypes"; import VCLCredentialTypesUIFormSchema from "./entities/VCLCredentialTypesUIFormSchema"; import VCLCredentialTypesUIFormSchemaDescriptor from "./entities/VCLCredentialTypesUIFormSchemaDescriptor"; import VCLDidJwk from "./entities/VCLDidJwk"; -import VCLError from "./entities/VCLError"; +import VCLError from "./entities/error/VCLError"; import VCLExchange from "./entities/VCLExchange"; import VCLExchangeDescriptor from "./entities/VCLExchangeDescriptor"; import VCLFinalizeOffersDescriptor from "./entities/VCLFinalizeOffersDescriptor"; import VCLGenerateOffersDescriptor from "./entities/VCLGenerateOffersDescriptor"; import VCLInitializationDescriptor from "./entities/VCLInitializationDescriptor"; -import VCLJwkPublic from "./entities/VCLJwkPublic"; +import VCLPublicJwk from "./entities/VCLPublicJwk"; import VCLJwt from "./entities/VCLJwt"; import VCLJwtDescriptor from "./entities/VCLJwtDescriptor"; import VCLJwtVerifiableCredentials from "./entities/VCLJwtVerifiableCredentials"; @@ -80,7 +80,7 @@ export default interface VCL { verifiedProfileDescriptor: VCLVerifiedProfileDescriptor ): Promise; - verifyJwt(jwt: VCLJwt, jwkPublic: VCLJwkPublic): Promise; + verifyJwt(jwt: VCLJwt, jwkPublic: VCLPublicJwk): Promise; generateSignedJwt(jwtDescriptor: VCLJwtDescriptor): Promise; diff --git a/packages/sdk/src/api/entities/VCLPresentationRequest.ts b/packages/sdk/src/api/entities/VCLPresentationRequest.ts index a952848..2664464 100644 --- a/packages/sdk/src/api/entities/VCLPresentationRequest.ts +++ b/packages/sdk/src/api/entities/VCLPresentationRequest.ts @@ -1,12 +1,12 @@ import VCLDeepLink from "./VCLDeepLink"; -import VCLJwkPublic from "./VCLJwkPublic"; +import VCLPublicJwk from "./VCLPublicJwk"; import VCLJwt from "./VCLJwt"; import VCLPushDelegate from "./VCLPushDelegate"; export default class VCLPresentationRequest { constructor( public readonly jwt: VCLJwt, - public readonly jwkPublic: VCLJwkPublic, + public readonly jwkPublic: VCLPublicJwk, public readonly deepLink: VCLDeepLink, public readonly pushDelegate: Nullish = null ) {} diff --git a/packages/sdk/src/api/entities/VCLJwkPublic.ts b/packages/sdk/src/api/entities/VCLPublicJwk.ts similarity index 66% rename from packages/sdk/src/api/entities/VCLJwkPublic.ts rename to packages/sdk/src/api/entities/VCLPublicJwk.ts index e546180..1bf8e7c 100644 --- a/packages/sdk/src/api/entities/VCLJwkPublic.ts +++ b/packages/sdk/src/api/entities/VCLPublicJwk.ts @@ -5,15 +5,15 @@ enum Format { base58 = "base58", } -export default class VCLJwkPublic { +export default class VCLPublicJwk { constructor(public valueStr: string, public valueJson: JSONObject) {} static readonly Format = Format; public static fromString(valueStr: string) { - return new VCLJwkPublic(valueStr, JSON.parse(valueStr)); + return new VCLPublicJwk(valueStr, JSON.parse(valueStr)); } public static fromJSON(valueJson: JSONObject) { - return new VCLJwkPublic(JSON.stringify(valueJson), valueJson); + return new VCLPublicJwk(JSON.stringify(valueJson), valueJson); } } diff --git a/packages/sdk/src/api/entities/VCLResult.ts b/packages/sdk/src/api/entities/VCLResult.ts index cae5d03..52c364b 100644 --- a/packages/sdk/src/api/entities/VCLResult.ts +++ b/packages/sdk/src/api/entities/VCLResult.ts @@ -1,4 +1,4 @@ -import VCLError from "./VCLError"; +import VCLError from "./error/VCLError"; export default class VCLResult { static Success = class extends VCLResult { diff --git a/packages/sdk/src/api/entities/VCLError.ts b/packages/sdk/src/api/entities/error/VCLError.ts similarity index 76% rename from packages/sdk/src/api/entities/VCLError.ts rename to packages/sdk/src/api/entities/error/VCLError.ts index 6333947..2a47745 100644 --- a/packages/sdk/src/api/entities/VCLError.ts +++ b/packages/sdk/src/api/entities/error/VCLError.ts @@ -1,12 +1,14 @@ +import VCLErrorCode from "./VCLErrorCode"; + export default class VCLError extends Error { payload: Nullish = null; error: Nullish = null; - errorCode: Nullish = null; + errorCode: string = VCLErrorCode.SdkError.toString(); statusCode: Nullish = null; constructor( error: Nullish = null, - errorCode: Nullish = null, + errorCode: string = VCLErrorCode.SdkError.toString(), message: Nullish = null, statusCode: Nullish = null ) { @@ -23,7 +25,7 @@ export default class VCLError extends Error { const payloadJson = JSON.parse(payload); let result = new VCLError( payloadJson?.[VCLError.KeyError] || null, - payloadJson?.[VCLError.KeyErrorCode] || null, + payloadJson?.[VCLError.KeyErrorCode] || VCLErrorCode.SdkError.toString(), payloadJson?.[VCLError.KeyMessage] || null, payloadJson?.[VCLError.KeyStatusCode] || null ); @@ -36,8 +38,12 @@ export default class VCLError extends Error { exception: Error, statusCode: number | null = null ): VCLError { - let result = new VCLError(null, null, exception.message, statusCode); - + let result = new VCLError( + null, + VCLErrorCode.SdkError.toString(), + exception.message, + statusCode + ); return result; } @@ -45,7 +51,7 @@ export default class VCLError extends Error { return { [VCLError.KeyPayload]: this.payload, [VCLError.KeyError]: this.error, - [VCLError.KeyErrorCode]: this.errorCode, + [VCLError.KeyErrorCode]: (this.errorCode || VCLErrorCode.SdkError.toString()), [VCLError.KeyMessage]: this.message, [VCLError.KeyStatusCode]: this.statusCode, }; diff --git a/packages/sdk/src/api/entities/error/VCLErrorCode.ts b/packages/sdk/src/api/entities/error/VCLErrorCode.ts new file mode 100644 index 0000000..d864467 --- /dev/null +++ b/packages/sdk/src/api/entities/error/VCLErrorCode.ts @@ -0,0 +1,20 @@ +enum VCLErrorCode { + // Initialization + RemoteServicesUrlsNotFount = "remote_services_urls_not_found", + InjectedServicesNotFount = "injected_services_not_found", + // Credential issuer verification error codes: + CredentialTypeNotRegistered = "credential_type_not_registered", + IssuerRequiresIdentityPermission = "issuer_requires_identity_permission", + IssuerRequiresNotaryPermission = "issuer_requires_notary_permission", + InvalidCredentialSubjectType = "invalid_credential_subject_type", + InvalidCredentialSubjectContext = "invalid_credential_subject_context", + IssuerUnexpectedPermissionFailure = "issuer_unexpected_permission_failure", + // DID consistent with the Deep Link + MismatchedRequestIssuerDid = "mismatched_request_issuer_did", + MismatchedOfferIssuerDid = "mismatched_offer_issuer_did", + MismatchedCredentialIssuerDid = "mismatched_credential_issuer_did", + MismatchedPresentationRequestInspectorDid = "mismatched_presentation_request_inspector_did", + // General error + SdkError = "sdk_error", +} +export default VCLErrorCode; diff --git a/packages/sdk/src/api/entities/VCLStatusCode.ts b/packages/sdk/src/api/entities/error/VCLStatusCode.ts similarity index 75% rename from packages/sdk/src/api/entities/VCLStatusCode.ts rename to packages/sdk/src/api/entities/error/VCLStatusCode.ts index e02344c..be22e2f 100644 --- a/packages/sdk/src/api/entities/VCLStatusCode.ts +++ b/packages/sdk/src/api/entities/error/VCLStatusCode.ts @@ -3,5 +3,4 @@ enum VCLStatusCode { VerificationError = 403, Undefined = -1, } - -export default VCLStatusCode; +export default VCLStatusCode; \ No newline at end of file diff --git a/packages/sdk/src/impl/VCLImpl.ts b/packages/sdk/src/impl/VCLImpl.ts index 08ab71b..27878a3 100644 --- a/packages/sdk/src/impl/VCLImpl.ts +++ b/packages/sdk/src/impl/VCLImpl.ts @@ -8,14 +8,14 @@ import VCLCredentialTypes from "../api/entities/VCLCredentialTypes"; import VCLCredentialTypesUIFormSchema from "../api/entities/VCLCredentialTypesUIFormSchema"; import VCLCredentialTypesUIFormSchemaDescriptor from "../api/entities/VCLCredentialTypesUIFormSchemaDescriptor"; import VCLDidJwk from "../api/entities/VCLDidJwk"; -import VCLError from "../api/entities/VCLError"; +import VCLError from "../api/entities/error/VCLError"; import VCLExchange from "../api/entities/VCLExchange"; import VCLExchangeDescriptor from "../api/entities/VCLExchangeDescriptor"; import VCLFinalizeOffersDescriptor from "../api/entities/VCLFinalizeOffersDescriptor"; import VCLGenerateOffersDescriptor from "../api/entities/VCLGenerateOffersDescriptor"; import VCLIdentificationSubmission from "../api/entities/VCLIdentificationSubmission"; import VCLInitializationDescriptor from "../api/entities/VCLInitializationDescriptor"; -import VCLJwkPublic from "../api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../api/entities/VCLPublicJwk"; import VCLJwt from "../api/entities/VCLJwt"; import VCLJwtDescriptor from "../api/entities/VCLJwtDescriptor"; import VCLJwtVerifiableCredentials from "../api/entities/VCLJwtVerifiableCredentials"; @@ -44,6 +44,7 @@ import "./extensions/DateExtensions"; import "./extensions/StringExtensions"; import "./extensions/ListExtensions"; import VCLResult from "../api/entities/VCLResult"; +import VCLErrorCode from "../api/entities/error/VCLErrorCode"; export class VCLImpl implements VCL { static TAG = VCLImpl.name; @@ -259,7 +260,7 @@ export class VCLImpl implements VCL { `did was not found in ${JSON.stringify( credentialManifestDescriptor )}`, - null, + VCLErrorCode.SdkError.toString(), null ); VCLLog.e( @@ -375,7 +376,7 @@ export class VCLImpl implements VCL { return result!; }; - verifyJwt = async (jwt: VCLJwt, jwkPublic: VCLJwkPublic) => { + verifyJwt = async (jwt: VCLJwt, jwkPublic: VCLPublicJwk) => { let isVerifiedResult = await this.jwtServiceUseCase.verifyJwt( jwt, jwkPublic diff --git a/packages/sdk/src/impl/data/infrastructure/jwt/JwtServiceImpl.ts b/packages/sdk/src/impl/data/infrastructure/jwt/JwtServiceImpl.ts index 24a5fc8..66916a3 100644 --- a/packages/sdk/src/impl/data/infrastructure/jwt/JwtServiceImpl.ts +++ b/packages/sdk/src/impl/data/infrastructure/jwt/JwtServiceImpl.ts @@ -8,7 +8,7 @@ import VCLJwtDescriptor from "../../../../api/entities/VCLJwtDescriptor"; import JwtService from "../../../domain/infrastructure/jwt/JwtService"; import crypto from "crypto"; import canonicalize from "canonicalize"; -import VCLJwkPublic from "../../../../api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../../../../api/entities/VCLPublicJwk"; export default class JwtServiceImpl implements JwtService { parse(jwt: string): Nullish { @@ -111,6 +111,6 @@ export default class JwtServiceImpl implements JwtService { private async generateJwkPublic(kid: string) { let publicJwk = await this.generateJwkSECP256K1(kid).toPublicJWK(); - return VCLJwkPublic.fromJSON(publicJwk); + return VCLPublicJwk.fromJSON(publicJwk); } } diff --git a/packages/sdk/src/impl/data/models/CountriesModelImpl.ts b/packages/sdk/src/impl/data/models/CountriesModelImpl.ts index f71f233..3de01e0 100644 --- a/packages/sdk/src/impl/data/models/CountriesModelImpl.ts +++ b/packages/sdk/src/impl/data/models/CountriesModelImpl.ts @@ -1,5 +1,5 @@ import VCLCountries from "../../../api/entities/VCLCountries"; -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLResult from "../../../api/entities/VCLResult"; import CountriesModel from "../../domain/models/CountriesModel"; import CountriesUseCase from "../../domain/usecases/CountriesModelUseCase"; diff --git a/packages/sdk/src/impl/data/models/CredentialTypeSchemasModelImpl.ts b/packages/sdk/src/impl/data/models/CredentialTypeSchemasModelImpl.ts index 202835d..872c580 100644 --- a/packages/sdk/src/impl/data/models/CredentialTypeSchemasModelImpl.ts +++ b/packages/sdk/src/impl/data/models/CredentialTypeSchemasModelImpl.ts @@ -1,5 +1,5 @@ import VCLCredentialTypeSchemas from "../../../api/entities/VCLCredentialTypeSchemas"; -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLResult from "../../../api/entities/VCLResult"; import CredentialTypeSchemasModel from "../../domain/models/CredentialTypeSchemasModel"; import CredentialTypeSchemasUseCase from "../../domain/usecases/CredentialTypeSchemasUseCase"; diff --git a/packages/sdk/src/impl/data/models/CredentialTypesModelImpl.ts b/packages/sdk/src/impl/data/models/CredentialTypesModelImpl.ts index 8b95a43..3b03795 100644 --- a/packages/sdk/src/impl/data/models/CredentialTypesModelImpl.ts +++ b/packages/sdk/src/impl/data/models/CredentialTypesModelImpl.ts @@ -1,5 +1,5 @@ import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLResult from "../../../api/entities/VCLResult"; import CredentialTypesModel from "../../domain/models/CredentialTypesModel"; import { CredentialTypesUseCase } from "../../domain/usecases/CredentialTypesUseCase"; diff --git a/packages/sdk/src/impl/data/repositories/CredentialManifestRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/CredentialManifestRepositoryImpl.ts index fb35de0..3654fa8 100644 --- a/packages/sdk/src/impl/data/repositories/CredentialManifestRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/CredentialManifestRepositoryImpl.ts @@ -1,6 +1,6 @@ import VCLCredentialManifest from "../../../api/entities/VCLCredentialManifest"; import VCLCredentialManifestDescriptor from "../../../api/entities/VCLCredentialManifestDescriptor"; -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLResult from "../../../api/entities/VCLResult"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import CredentialManifestRepository from "../../domain/repositories/CredentialManifestRepository"; diff --git a/packages/sdk/src/impl/data/repositories/CredentialTypesRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/CredentialTypesRepositoryImpl.ts index 90f56d6..69232ab 100644 --- a/packages/sdk/src/impl/data/repositories/CredentialTypesRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/CredentialTypesRepositoryImpl.ts @@ -1,6 +1,6 @@ import VCLCredentialType from "../../../api/entities/VCLCredentialType"; import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLResult from "../../../api/entities/VCLResult"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import CredentialTypesRepository from "../../domain/repositories/CredentialTypesRepository"; diff --git a/packages/sdk/src/impl/data/repositories/ExchangeProgressRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/ExchangeProgressRepositoryImpl.ts index 9f5f653..5eee749 100644 --- a/packages/sdk/src/impl/data/repositories/ExchangeProgressRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/ExchangeProgressRepositoryImpl.ts @@ -1,4 +1,4 @@ -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLExchange from "../../../api/entities/VCLExchange"; import VCLExchangeDescriptor from "../../../api/entities/VCLExchangeDescriptor"; import VCLResult from "../../../api/entities/VCLResult"; diff --git a/packages/sdk/src/impl/data/repositories/FinalizeOffersRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/FinalizeOffersRepositoryImpl.ts index ed315fe..fef7ef6 100644 --- a/packages/sdk/src/impl/data/repositories/FinalizeOffersRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/FinalizeOffersRepositoryImpl.ts @@ -1,4 +1,4 @@ -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLFinalizeOffersDescriptor from "../../../api/entities/VCLFinalizeOffersDescriptor"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLResult from "../../../api/entities/VCLResult"; diff --git a/packages/sdk/src/impl/data/repositories/GenerateOffersRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/GenerateOffersRepositoryImpl.ts index eab451e..53b1459 100644 --- a/packages/sdk/src/impl/data/repositories/GenerateOffersRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/GenerateOffersRepositoryImpl.ts @@ -1,4 +1,4 @@ -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLGenerateOffersDescriptor from "../../../api/entities/VCLGenerateOffersDescriptor"; import VCLOffers from "../../../api/entities/VCLOffers"; import VCLResult from "../../../api/entities/VCLResult"; diff --git a/packages/sdk/src/impl/data/repositories/JwtServiceRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/JwtServiceRepositoryImpl.ts index ddfa380..bb76d27 100644 --- a/packages/sdk/src/impl/data/repositories/JwtServiceRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/JwtServiceRepositoryImpl.ts @@ -1,7 +1,7 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; -import VCLError from "../../../api/entities/VCLError"; -import VCLJwkPublic from "../../../api/entities/VCLJwkPublic"; +import VCLError from "../../../api/entities/error/VCLError"; +import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; import VCLResult from "../../../api/entities/VCLResult"; @@ -25,7 +25,7 @@ export default class JwtServiceRepositoryImpl implements JwtServiceRepository { } async verifyJwt( jwt: VCLJwt, - jwkPublic: VCLJwkPublic + jwkPublic: VCLPublicJwk ): Promise> { try { let it = await this.jwtService.verify(jwt, jwkPublic.valueStr); diff --git a/packages/sdk/src/impl/data/repositories/OrganizationsRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/OrganizationsRepositoryImpl.ts index da2d44e..0863bf6 100644 --- a/packages/sdk/src/impl/data/repositories/OrganizationsRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/OrganizationsRepositoryImpl.ts @@ -1,4 +1,4 @@ -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLOrganization from "../../../api/entities/VCLOrganization"; import VCLOrganizations from "../../../api/entities/VCLOrganizations"; import VCLOrganizationsSearchDescriptor from "../../../api/entities/VCLOrganizationsSearchDescriptor"; diff --git a/packages/sdk/src/impl/data/repositories/PresentationRequestRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/PresentationRequestRepositoryImpl.ts index 103adc5..6c20bf9 100644 --- a/packages/sdk/src/impl/data/repositories/PresentationRequestRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/PresentationRequestRepositoryImpl.ts @@ -1,4 +1,4 @@ -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLPresentationRequest from "../../../api/entities/VCLPresentationRequest"; import VCLPresentationRequestDescriptor from "../../../api/entities/VCLPresentationRequestDescriptor"; import VCLResult from "../../../api/entities/VCLResult"; diff --git a/packages/sdk/src/impl/data/repositories/ResolveKidRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/ResolveKidRepositoryImpl.ts index 37850bd..f519188 100644 --- a/packages/sdk/src/impl/data/repositories/ResolveKidRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/ResolveKidRepositoryImpl.ts @@ -1,4 +1,4 @@ -import VCLJwkPublic from "../../../api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLResult from "../../../api/entities/VCLResult"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import ResolveKidRepository from "../../domain/repositories/ResolveKidRepository"; @@ -8,10 +8,10 @@ import Urls, { HeaderKeys, HeaderValues } from "./Urls"; export default class ResolveKidRepositoryImpl implements ResolveKidRepository { constructor(private readonly networkService: NetworkService) {} - async getPublicKey(kid: string): Promise> { + async getPublicKey(kid: string): Promise> { let result = await this.networkService.sendRequest({ endpoint: - Urls.ResolveKid + kid + `?format=${VCLJwkPublic.Format.jwk}`, + Urls.ResolveKid + kid + `?format=${VCLPublicJwk.Format.jwk}`, method: HttpMethod.GET, headers: { [HeaderKeys.XVnfProtocolVersion]: @@ -28,7 +28,7 @@ export default class ResolveKidRepositoryImpl implements ResolveKidRepository { } return new VCLResult.Success( - VCLJwkPublic.fromJSON(publicKeyResponse!.payload) + VCLPublicJwk.fromJSON(publicKeyResponse!.payload) ); } } diff --git a/packages/sdk/src/impl/data/repositories/SubmissionRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/SubmissionRepositoryImpl.ts index a61df8b..477f2f9 100644 --- a/packages/sdk/src/impl/data/repositories/SubmissionRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/SubmissionRepositoryImpl.ts @@ -1,4 +1,4 @@ -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLExchange from "../../../api/entities/VCLExchange"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLResult from "../../../api/entities/VCLResult"; diff --git a/packages/sdk/src/impl/data/usecases/CredentialManifestUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/CredentialManifestUseCaseImpl.ts index d896ea9..a327385 100644 --- a/packages/sdk/src/impl/data/usecases/CredentialManifestUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/CredentialManifestUseCaseImpl.ts @@ -1,7 +1,7 @@ import VCLCredentialManifest from "../../../api/entities/VCLCredentialManifest"; import VCLCredentialManifestDescriptor from "../../../api/entities/VCLCredentialManifestDescriptor"; -import VCLError from "../../../api/entities/VCLError"; -import VCLJwkPublic from "../../../api/entities/VCLJwkPublic"; +import VCLError from "../../../api/entities/error/VCLError"; +import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLResult from "../../../api/entities/VCLResult"; import CredentialManifestRepository from "../../domain/repositories/CredentialManifestRepository"; @@ -54,7 +54,7 @@ export default class CredentialManifestUseCaseImpl } async onResolvePublicKeySuccess( - jwkPublic: VCLJwkPublic, + jwkPublic: VCLPublicJwk, jwt: VCLJwt, credentialManifestDescriptor: VCLCredentialManifestDescriptor ): Promise> { diff --git a/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts index ec90cea..89b95c9 100644 --- a/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts @@ -1,4 +1,4 @@ -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLFinalizeOffersDescriptor from "../../../api/entities/VCLFinalizeOffersDescriptor"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtVerifiableCredentials from "../../../api/entities/VCLJwtVerifiableCredentials"; diff --git a/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts index 9e8ff9e..11fdff5 100644 --- a/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts @@ -1,6 +1,6 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; -import VCLJwkPublic from "../../../api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; import VCLResult from "../../../api/entities/VCLResult"; @@ -14,7 +14,7 @@ export default class JwtServiceUseCaseImpl implements JwtServiceUseCase { return this.jwtServiceRepository.generateDidJwk(didJwkDescriptor); } - verifyJwt(jwt: VCLJwt, jwkPublic: VCLJwkPublic) { + verifyJwt(jwt: VCLJwt, jwkPublic: VCLPublicJwk) { return this.jwtServiceRepository.verifyJwt(jwt, jwkPublic); } generateSignedJwt(jwtDescriptor: VCLJwtDescriptor) { diff --git a/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts index 30fb8f3..815fea7 100644 --- a/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts @@ -1,5 +1,5 @@ -import VCLError from "../../../api/entities/VCLError"; -import VCLJwkPublic from "../../../api/entities/VCLJwkPublic"; +import VCLError from "../../../api/entities/error/VCLError"; +import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLPresentationRequest from "../../../api/entities/VCLPresentationRequest"; import VCLPresentationRequestDescriptor from "../../../api/entities/VCLPresentationRequestDescriptor"; @@ -81,7 +81,7 @@ export default class PresentationRequestUseCaseImpl } async onResolvePublicKeySuccess( - jwkPublic: VCLJwkPublic, + jwkPublic: VCLPublicJwk, jwt: VCLJwt, presentationRequestDescriptor: VCLPresentationRequestDescriptor ): Promise> { diff --git a/packages/sdk/src/impl/domain/models/Initializable.ts b/packages/sdk/src/impl/domain/models/Initializable.ts index 8c51999..5b19173 100644 --- a/packages/sdk/src/impl/domain/models/Initializable.ts +++ b/packages/sdk/src/impl/domain/models/Initializable.ts @@ -1,4 +1,4 @@ -import VCLError from "../../../api/entities/VCLError"; +import VCLError from "../../../api/entities/error/VCLError"; import VCLResult from "../../../api/entities/VCLResult"; export default interface Initializable { diff --git a/packages/sdk/src/impl/domain/repositories/JwtServiceRepository.ts b/packages/sdk/src/impl/domain/repositories/JwtServiceRepository.ts index a437645..453cd2c 100644 --- a/packages/sdk/src/impl/domain/repositories/JwtServiceRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/JwtServiceRepository.ts @@ -2,7 +2,7 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; -import VCLJwkPublic from "../../../api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; import VCLResult from "../../../api/entities/VCLResult"; @@ -12,7 +12,7 @@ export default interface JwtServiceRepository { verifyJwt( jwt: VCLJwt, - jwkPublic: VCLJwkPublic + jwkPublic: VCLPublicJwk ): Promise>; generateSignedJwt( diff --git a/packages/sdk/src/impl/domain/repositories/ResolveKidRepository.ts b/packages/sdk/src/impl/domain/repositories/ResolveKidRepository.ts index d338e7c..332998b 100644 --- a/packages/sdk/src/impl/domain/repositories/ResolveKidRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/ResolveKidRepository.ts @@ -1,8 +1,8 @@ // package io.velocitycareerlabs.impl.domain.repositories -import VCLJwkPublic from "../../../api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLResult from "../../../api/entities/VCLResult"; export default interface ResolveKidRepository { - getPublicKey(kid: string): Promise>; + getPublicKey(kid: string): Promise>; } diff --git a/packages/sdk/src/impl/domain/usecases/JwtServiceUseCase.ts b/packages/sdk/src/impl/domain/usecases/JwtServiceUseCase.ts index e87cefd..f19b0f4 100644 --- a/packages/sdk/src/impl/domain/usecases/JwtServiceUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/JwtServiceUseCase.ts @@ -1,6 +1,6 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; -import VCLJwkPublic from "../../../api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; import VCLResult from "../../../api/entities/VCLResult"; @@ -8,7 +8,7 @@ import VCLResult from "../../../api/entities/VCLResult"; export default interface JwtServiceUseCase { verifyJwt( jwt: VCLJwt, - jwkPublic: VCLJwkPublic + jwkPublic: VCLPublicJwk ): Promise>; generateSignedJwt( diff --git a/packages/sdk/src/impl/utils/InitializationWatcher.ts b/packages/sdk/src/impl/utils/InitializationWatcher.ts index 30f5ee7..2481a38 100644 --- a/packages/sdk/src/impl/utils/InitializationWatcher.ts +++ b/packages/sdk/src/impl/utils/InitializationWatcher.ts @@ -1,4 +1,4 @@ -import VCLError from "../../api/entities/VCLError"; +import VCLError from "../../api/entities/error/VCLError"; export default class InitializationWatcher { private initCount: number = 0; diff --git a/packages/sdk/src/impl/utils/ProfileServiceTypeVerifier.ts b/packages/sdk/src/impl/utils/ProfileServiceTypeVerifier.ts index 457f1ff..6e0b833 100644 --- a/packages/sdk/src/impl/utils/ProfileServiceTypeVerifier.ts +++ b/packages/sdk/src/impl/utils/ProfileServiceTypeVerifier.ts @@ -1,10 +1,11 @@ -import VCLError from "../../api/entities/VCLError"; +import VCLError from "../../api/entities/error/VCLError"; import VCLResult from "../../api/entities/VCLResult"; import VCLServiceTypes from "../../api/entities/VCLServiceTypes"; -import VCLStatusCode from "../../api/entities/VCLStatusCode"; +import VCLStatusCode from "../../api/entities/error/VCLStatusCode"; import VCLVerifiedProfile from "../../api/entities/VCLVerifiedProfile"; import VCLVerifiedProfileDescriptor from "../../api/entities/VCLVerifiedProfileDescriptor"; import VerifiedProfileUseCase from "../domain/usecases/VerifiedProfileUseCase"; +import VCLErrorCode from "../../api/entities/error/VCLErrorCode"; export class ProfileServiceTypeVerifier { constructor( @@ -48,7 +49,7 @@ export class ProfileServiceTypeVerifier { profileName: verifiedProfile.name, message: `Wrong service type - expected: ${expectedServiceTypes.all}, found: ${verifiedProfile.serviceTypes.all}`, }), - null, + VCLErrorCode.SdkError.toString(), null, VCLStatusCode.VerificationError ); diff --git a/packages/sdk/test/entities/VCLError.test.ts b/packages/sdk/test/entities/VCLError.test.ts index 4bc9280..1b45f93 100644 --- a/packages/sdk/test/entities/VCLError.test.ts +++ b/packages/sdk/test/entities/VCLError.test.ts @@ -1,4 +1,4 @@ -import VCLError from "../../src/api/entities/VCLError"; +import VCLError from "../../src/api/entities/error/VCLError"; import { ErrorMocks } from "../infrastructure/resources/valid/ErrorMocks"; import "../../src/impl/extensions/StringExtensions"; import "../../src/impl/extensions/ListExtensions"; @@ -46,13 +46,16 @@ describe("VCLError Tests", () => { }); test("testErrorToJsonFromProperties", () => { - const error2 = new VCLError( + const error = new VCLError( ErrorMocks.Error, ErrorMocks.ErrorCode, ErrorMocks.Message, ErrorMocks.StatusCode ); - const errorJsonObject = error2.jsonObject; + const errorJsonObject = error.jsonObject; + + console.log("--------------------"); + console.log(JSON.stringify(errorJsonObject)); expect(errorJsonObject[VCLError.KeyPayload]).toBeFalsy(); expect(errorJsonObject[VCLError.KeyError]).toBe(ErrorMocks.Error); diff --git a/packages/sdk/test/entities/VCLJwkPublic.test.ts b/packages/sdk/test/entities/VCLPublicJwk.test.ts similarity index 59% rename from packages/sdk/test/entities/VCLJwkPublic.test.ts rename to packages/sdk/test/entities/VCLPublicJwk.test.ts index 1af2ae1..d8a9715 100644 --- a/packages/sdk/test/entities/VCLJwkPublic.test.ts +++ b/packages/sdk/test/entities/VCLPublicJwk.test.ts @@ -1,18 +1,18 @@ -import VCLJwkPublic from "../../src/api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../../src/api/entities/VCLPublicJwk"; import { JwtServiceMocks } from "../infrastructure/resources/valid/JwtServiceMocks"; -describe("VCLJwkPublic Tests", () => { - let subject: VCLJwkPublic; +describe("VCLPublicJwk Tests", () => { + let subject: VCLPublicJwk; const jwkJson = JSON.parse(JwtServiceMocks.JWK); test("testJwkPublicFromStr", () => { - subject = VCLJwkPublic.fromString(JwtServiceMocks.JWK); + subject = VCLPublicJwk.fromString(JwtServiceMocks.JWK); expect(subject.valueStr).toBe(JwtServiceMocks.JWK); }); test("testJwkPublicFromJson", () => { - subject = VCLJwkPublic.fromJSON(jwkJson); + subject = VCLPublicJwk.fromJSON(jwkJson); expect(subject.valueJson).toEqual(jwkJson); }); diff --git a/packages/sdk/test/infrastructure/resources/valid/JwtServiceMocks.ts b/packages/sdk/test/infrastructure/resources/valid/JwtServiceMocks.ts index 102c01f..b76f5d2 100644 --- a/packages/sdk/test/infrastructure/resources/valid/JwtServiceMocks.ts +++ b/packages/sdk/test/infrastructure/resources/valid/JwtServiceMocks.ts @@ -1,5 +1,5 @@ import VCLJwt, { SignedJWT } from "../../../../src/api/entities/VCLJwt"; -import VCLJwkPublic from "../../../../src/api/entities/VCLJwkPublic"; +import VCLPublicJwk from "../../../../src/api/entities/VCLPublicJwk"; class JwtServiceMocks { static AdamSmithEmailJwt = "eyJ0eXAiOiJKV1QiLCJqd2siOnsiY3J2Ijoic2VjcDI1NmsxIiwieCI6IkFxcl9HRHVoeE5fSHFHZ0E4YmVjeW9NNkZBUzZMMm9rVWFoc21GaTJRSUkiLCJ5IjoiaXI0a2Z1bVRYTHlCdjlPNUlJNVJzVmhVdnNvWUZRVURnWk0yQXJCSkxxYyIsImt0eSI6IkVDIiwia2lkIjoiLTNUNjZ1WHJ4Y1JWZ3E4VnhwcW43NXFTbDBrN0dfcDNYMlRIdW9jSFlycyIsImFsZyI6IkVTMjU2SyJ9LCJhbGciOiJFUzI1NksifQ.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIkVtYWlsIiwiVmVyaWZpYWJsZUNyZWRlbnRpYWwiXSwiY3JlZGVudGlhbFN0YXR1cyI6eyJpZCI6Imh0dHBzOi8vY3JlZGVudGlhbHN0YXR1cy52ZWxvY2l0eWNhcmVlcmxhYnMuaW8iLCJ0eXBlIjoiVmVsb2NpdHlSZXZvY2F0aW9uUmVnaXN0cnkifSwiY3JlZGVudGlhbFN1YmplY3QiOnsiZW1haWwiOiJhZGFtLnNtaXRoQGV4YW1wbGUuY29tIn19LCJpc3MiOiJkaWQ6ZXRoci4weDBiMTU0ZGE0OGQwZjIxM2MyNmM0YjFkMDQwZGM1ZmYxZGJmOTlmZmEiLCJqdGkiOiJkaWQ6ZXRoci4weDQ5YjhlMzQ2NzYyZGYwYzc4NzkyZDAzZWM2Zjg0NGVlYjEyMDM2YzgiLCJpYXQiOjE2MDkwNzgzMTQsIm5iZiI6MTYwOTA3ODMxNH0.Pk3_mf7OTHATkOis4MBamUlerGepcB0ke-DFvhe7potRRCwiuo4v96vkOGPW_Rib0Rk6xV1rPXl8Z-UY2_TbvQ"; @@ -30,7 +30,7 @@ class JwtServiceMocks { this.splittedPresentationRequestJwt[2] ); - static JwkPublic = VCLJwkPublic.fromString(this.JWK); + static JwkPublic = VCLPublicJwk.fromString(this.JWK); static JWT = new VCLJwt(this.SignedJWT); }