From 70778e57eab008cea13f18a408fb4ca010a6244f Mon Sep 17 00:00:00 2001 From: Michael Avoyan Date: Wed, 29 May 2024 13:21:25 +0300 Subject: [PATCH 1/2] chore: remove `VCLResult` and use `Promise` only + fixes --- .eslintrc.js | 12 +- package.json | 5 + packages/sample-server/package.json | 16 +- packages/sample-server/src/global.ts | 18 ++ .../sample-server/src/routes/users/getUser.ts | 1 - .../sample-server/test/initalization.test.ts | 63 +--- .../sample-server/test/mocks/DidJwkMocks.ts | 20 ++ .../test/mocks/jwt/JwtSignServiceMock.ts | 22 ++ .../test/mocks/jwt/JwtVerifyServiceMock.ts | 9 + .../test/mocks/key/KeyServiceMock.ts | 10 + packages/sdk/package.json | 11 +- packages/sdk/src/api/VCL.ts | 10 +- .../src/api/entities/VCLCredentialManifest.ts | 30 ++ .../sdk/src/api/entities/VCLCredentialType.ts | 12 +- packages/sdk/src/api/entities/VCLDidJwk.ts | 4 +- .../src/api/entities/VCLExchangeDescriptor.ts | 4 - .../entities/VCLFinalizeOffersDescriptor.ts | 11 +- .../entities/VCLIdentificationSubmission.ts | 4 - .../api/entities/VCLPresentationSubmission.ts | 2 - packages/sdk/src/api/entities/VCLResult.ts | 35 --- .../sdk/src/api/entities/VCLSubmission.ts | 8 +- .../src/api/entities/VCLVerifiedProfile.ts | 39 +-- .../sdk/src/api/entities/error/VCLError.ts | 16 +- .../VCLCryptoServicesDescriptor.ts | 6 +- .../VCLInitializationDescriptor.ts | 2 +- packages/sdk/src/api/jwt/VCLJwtSignService.ts | 14 +- .../sdk/src/api/jwt/VCLJwtVerifyService.ts | 3 +- packages/sdk/src/api/keys/VCLKeyService.ts | 5 +- packages/sdk/src/global.ts | 3 + packages/sdk/src/impl/VCLImpl.ts | 274 +++++++----------- packages/sdk/src/impl/VclBlocksProvider.ts | 5 +- .../data/infrastructure/jwt/JwtServiceImpl.ts | 2 +- .../network/NetworkServiceImpl.ts | 9 +- .../impl/data/models/CountriesModelImpl.ts | 13 +- .../models/CredentialTypeSchemasModelImpl.ts | 11 +- .../data/models/CredentialTypesModelImpl.ts | 9 +- .../repositories/CountriesRepositoryImpl.ts | 24 +- .../CredentialManifestRepositoryImpl.ts | 21 +- .../CredentialTypeSchemaRepositoryImpl.ts | 20 +- .../CredentialTypesRepositoryImpl.ts | 50 ++-- ...edentialTypesUIFormSchemaRepositoryImpl.ts | 26 +- .../ExchangeProgressRepositoryImpl.ts | 21 +- .../FinalizeOffersRepositoryImpl.ts | 39 +-- .../GenerateOffersRepositoryImpl.ts | 24 +- .../repositories/JwtServiceRepositoryImpl.ts | 55 ++-- .../repositories/KeyServiceRepositoryImpl.ts | 3 +- .../OrganizationsRepositoryImpl.ts | 19 +- .../PresentationRequestRepositoryImpl.ts | 26 +- .../repositories/ResolveKidRepositoryImpl.ts | 15 +- .../repositories/SubmissionRepositoryImpl.ts | 33 +-- .../VerifiedProfileRepositoryImpl.ts | 17 +- .../usecases/CountriesModelUseCaseImpl.ts | 9 +- .../usecases/CredentialManifestUseCaseImpl.ts | 64 ++-- .../CredentialTypeSchemasUseCaseImpl.ts | 22 +- .../CredentialTypesUIFormSchemaUseCaseImpl.ts | 17 +- .../usecases/CredentialTypesUseCaseImpl.ts | 11 +- .../usecases/ExchangeProgressUseCaseImpl.ts | 23 +- .../usecases/FinalizeOffersUseCaseImpl.ts | 82 ++---- .../usecases/GenerateOffersUseCaseImpl.ts | 16 +- .../data/usecases/JwtServiceUseCaseImpl.ts | 15 +- .../data/usecases/KeyServiceUseCaseImpl.ts | 11 +- .../data/usecases/OrganizationsUseCaseImpl.ts | 13 +- .../PresentationRequestUseCaseImpl.ts | 79 ++--- .../data/usecases/SubmissionUseCaseImpl.ts | 43 ++- .../usecases/VerifiedProfileUseCaseImpl.ts | 20 +- .../domain/infrastructure/jwt/JwtService.ts | 20 -- .../infrastructure/network/NetworkService.ts | 7 +- .../impl/domain/models/IdentificationModel.ts | 6 +- .../src/impl/domain/models/Initializable.ts | 2 +- .../repositories/CountriesRepository.ts | 3 +- .../CredentialManifestRepository.ts | 3 +- .../CredentialTypeSchemaRepository.ts | 3 +- .../repositories/CredentialTypesRepository.ts | 5 +- .../CredentialTypesUIFormSchemaRepository.ts | 5 +- .../ExchangeProgressRepository.ts | 5 +- .../repositories/FinalizeOffersRepository.ts | 11 +- .../repositories/GenerateOffersRepository.ts | 7 +- .../repositories/JwtServiceRepository.ts | 11 +- .../repositories/KeyServiceRepository.ts | 5 +- .../repositories/OrganizationsRepository.ts | 5 +- .../PresentationRequestRepository.ts | 5 +- .../repositories/ResolveKidRepository.ts | 5 +- .../repositories/SubmissionRepository.ts | 5 +- .../repositories/VerifiedProfileRepository.ts | 6 +- .../domain/usecases/CountriesModelUseCase.ts | 3 +- .../usecases/CredentialManifestUseCase.ts | 4 +- .../usecases/CredentialTypeSchemasUseCase.ts | 11 +- .../CredentialTypesUIFormSchemaUseCase.ts | 11 +- .../domain/usecases/CredentialTypesUseCase.ts | 3 +- .../usecases/ExchangeProgressUseCase.ts | 3 +- .../domain/usecases/FinalizeOffersUseCase.ts | 7 +- .../domain/usecases/GenerateOffersUseCase.ts | 7 +- .../impl/domain/usecases/JwtServiceUseCase.ts | 6 +- .../impl/domain/usecases/KeyServiceUseCase.ts | 3 +- .../domain/usecases/OrganizationsUseCase.ts | 3 +- .../usecases/PresentationRequestUseCase.ts | 3 +- .../impl/domain/usecases/SubmissionUseCase.ts | 7 +- .../domain/usecases/VerifiedProfileUseCase.ts | 5 +- .../src/impl/extensions/StringExtensions.ts | 1 - .../impl/utils/ProfileServiceTypeVerifier.ts | 52 ++-- packages/sdk/src/index.ts | 6 +- packages/sdk/test/NetworkServiceSuccess.ts | 10 +- .../entities/VCLCredentialManifest.test.ts | 28 ++ packages/sdk/test/entities/VCLError.test.ts | 3 - .../VCLFinalizeOffersDescriptor.test.ts | 64 ++++ packages/sdk/test/entities/VCLJwt.test.ts | 2 +- .../sdk/test/entities/VCLSubmission.test.ts | 3 +- .../resources/jwt/JwtSignServiceMock.ts | 12 +- .../resources/jwt/JwtVerifyServiceMock.ts | 7 +- .../resources/key/KeyServiceMock.ts | 11 +- .../resources/valid/CountriesMocks.ts | 101 +++++++ .../valid/CredentialTypeSchemaMocks.ts | 73 +++++ .../resources/valid/CredentialTypesMocks.ts | 33 +++ .../resources/valid/DidJwkMocks.ts | 2 +- .../resources/valid/ExchangeProgressMocks.ts | 8 + .../valid/IdentificationSubmissionMocks.ts | 1 - .../resources/valid/OrganizationsMocks.ts | 31 ++ .../test/usecases/CountriesUseCase.test.ts | 31 ++ .../CredentialManifestUseCase.test.ts | 12 +- .../CredentialTypeSchemaUseCase.test.ts | 23 ++ ...CredentialTypesUIFormSchemaUseCase.test.ts | 17 +- .../usecases/CredentialTypesUseCase.test.ts | 94 ++++++ .../usecases/ExchangeProgressUseCase.test.ts | 49 ++++ .../usecases/GenerateOffersUseCase.test.ts | 14 +- .../IdentificationSubmissionUseCase.test.ts | 36 +-- .../usecases/OrganizationsUseCase.test.ts | 31 ++ .../PresentationRequestUseCase.test.ts | 46 ++- .../PresentationSubmissionUseCase.test.ts | 18 +- .../usecases/VerifiedProfileUseCase.test.ts | 47 +++ yarn.lock | 21 +- 130 files changed, 1354 insertions(+), 1264 deletions(-) create mode 100644 packages/sample-server/src/global.ts create mode 100644 packages/sample-server/test/mocks/DidJwkMocks.ts create mode 100644 packages/sample-server/test/mocks/jwt/JwtSignServiceMock.ts create mode 100644 packages/sample-server/test/mocks/jwt/JwtVerifyServiceMock.ts create mode 100644 packages/sample-server/test/mocks/key/KeyServiceMock.ts delete mode 100644 packages/sdk/src/api/entities/VCLResult.ts rename packages/sdk/src/api/entities/{ => initialization}/VCLCryptoServicesDescriptor.ts (58%) rename packages/sdk/src/api/entities/{ => initialization}/VCLInitializationDescriptor.ts (85%) delete mode 100644 packages/sdk/src/impl/domain/infrastructure/jwt/JwtService.ts create mode 100644 packages/sdk/test/entities/VCLCredentialManifest.test.ts create mode 100644 packages/sdk/test/entities/VCLFinalizeOffersDescriptor.test.ts create mode 100644 packages/sdk/test/infrastructure/resources/valid/CountriesMocks.ts create mode 100644 packages/sdk/test/infrastructure/resources/valid/CredentialTypeSchemaMocks.ts create mode 100644 packages/sdk/test/infrastructure/resources/valid/CredentialTypesMocks.ts create mode 100644 packages/sdk/test/infrastructure/resources/valid/ExchangeProgressMocks.ts create mode 100644 packages/sdk/test/infrastructure/resources/valid/OrganizationsMocks.ts create mode 100644 packages/sdk/test/usecases/CountriesUseCase.test.ts create mode 100644 packages/sdk/test/usecases/CredentialTypeSchemaUseCase.test.ts create mode 100644 packages/sdk/test/usecases/CredentialTypesUseCase.test.ts create mode 100644 packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts create mode 100644 packages/sdk/test/usecases/OrganizationsUseCase.test.ts create mode 100644 packages/sdk/test/usecases/VerifiedProfileUseCase.test.ts diff --git a/.eslintrc.js b/.eslintrc.js index d824982..2269727 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -39,19 +39,21 @@ module.exports = { jest: true, }, rules: { - 'better-mutation/no-mutating-functions': 'off', - 'better-mutation/no-mutating-methods': 'off', - 'better-mutation/no-mutation': 'off', - 'max-nested-callbacks': ['error', 8], + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + 'no-undef': 'off', + '@typescript-eslint/no-explicit-any': 'off', + 'unused-imports/no-unused-vars': 'error', }, }, ], rules: { '@typescript-eslint/no-unused-vars': 'off', '@typescript-eslint/no-empty-interface': 'off', - 'no-unused-vars': 'off', '@typescript-eslint/no-non-null-assertion': 'off', 'no-undef': 'off', '@typescript-eslint/no-explicit-any': 'off', + 'unused-imports/no-unused-vars': 'error', } }; diff --git a/package.json b/package.json index 740ca42..04f3bc0 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,11 @@ "private": true, "author": "Andres Olave", "license": "Apache 2.0", + "scripts": { + "lint": "eslint . --ext .js,.ts,.tsx", + "lint:fix": "eslint --fix --ext .js,.ts,.tsx .", + "test": "jest" + }, "engines": { "node": ">= 18.0.0" }, diff --git a/packages/sample-server/package.json b/packages/sample-server/package.json index 8046654..4168eb2 100644 --- a/packages/sample-server/package.json +++ b/packages/sample-server/package.json @@ -3,12 +3,12 @@ "version": "0.0.1", "description": "VNF Wallet Sample Nodejs Server", "scripts": { - "lint": "eslint .", - "lint:fix": "eslint --fix --ext .js .", + "lint": "eslint . --ext .js,.ts,.tsx", + "lint:fix": "eslint --fix --ext .js,.ts,.tsx .", + "test": "jest", "dev": "NODE_ENV=dev ts-node-dev --log-error --files ./src/server.ts", "build": "tsc -p tsconfig.json", - "start": "NODE_ENV=production node dist/server.js", - "test": "jest" + "start": "NODE_ENV=production node dist/server.js" }, "author": "Andres Olave", "license": "Apache-2.0", @@ -19,26 +19,26 @@ "@fastify/autoload": "~5.7.1", "env-var": "~7.3.0", "fastify": "~4.15.0", - "@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.8.35" + "@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.9.0" }, "devDependencies": { "@jest/globals": "~29.5.0", "@types/jest": "~29.5.0", "@types/node": "~18.15.10", + "chokidar": "^3.5.3", "@typescript-eslint/eslint-plugin": "~5.57.0", "@typescript-eslint/parser": "~5.57.0", - "chokidar": "^3.5.3", "eslint": "~8.57.0", - "eslint-config-prettier": "~8.8.0", + "eslint-config-prettier": "~9.1.0", "eslint-plugin-prettier": "~4.2.1", "eslint-plugin-autofix": "^1.0.0", "eslint-plugin-better-mutation": "1.4.0", "eslint-plugin-import": "^2.22.0", "eslint-plugin-prefer-arrow-functions": "^3.0.1", + "eslint-plugin-unused-imports": "^4.0.0", "jest": "~29.5.0", "json-schema-to-ts": "~2.7.2", "pino-pretty": "~10.0.0", - "prettier": "~2.8.7", "tree-kill": "^1.2.2", "ts-jest": "~29.0.5", "ts-node-dev": "^2.0.0", diff --git a/packages/sample-server/src/global.ts b/packages/sample-server/src/global.ts new file mode 100644 index 0000000..94f74c5 --- /dev/null +++ b/packages/sample-server/src/global.ts @@ -0,0 +1,18 @@ +// eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars +interface String { + getQueryParameters(): Map; + appendQueryParams(queryParams: string): string; + getUrlSubPath(subPathPrefix: string): string | null | undefined; + randomString(length: number): string; +} + +// eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars +interface Array { + toJsonArray(): any[]; +} + +// eslint-disable-next-line unused-imports/no-unused-vars +interface Date { + addDaysToNow(days: number): Date; + equalsTo(date: Date): boolean; +} \ No newline at end of file diff --git a/packages/sample-server/src/routes/users/getUser.ts b/packages/sample-server/src/routes/users/getUser.ts index 35be7d7..5b4a989 100644 --- a/packages/sample-server/src/routes/users/getUser.ts +++ b/packages/sample-server/src/routes/users/getUser.ts @@ -17,7 +17,6 @@ interface getUserRequestInterface { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export default async function routes(fastify: FastifyInstance) { - const summary = "Get user details"; fastify.get( "/:userId", { diff --git a/packages/sample-server/test/initalization.test.ts b/packages/sample-server/test/initalization.test.ts index dd68d99..7bbb504 100644 --- a/packages/sample-server/test/initalization.test.ts +++ b/packages/sample-server/test/initalization.test.ts @@ -4,20 +4,13 @@ import app from "../src/app"; import { FastifyInstance } from "fastify"; import { VCLImpl } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/impl/VCLImpl"; -import VCLInitializationDescriptor from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLInitializationDescriptor"; +import VCLInitializationDescriptor from "packages/sdk/src/api/entities/initialization/VCLInitializationDescriptor"; import VCLCountries from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLCountries"; import VCLEnvironment from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/VCLEnvironment"; -import VCLCryptoServicesDescriptor from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLCryptoServicesDescriptor"; -import VCLKeyService from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/keys/VCLKeyService" -import VCLDidJwk from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLDidJwk"; -import VCLDidJwkDescriptor from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLDidJwkDescriptor"; -import VCLResult from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLResult"; -import VCLPublicJwk from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLPublicJwk"; -import VCLJwtSignService from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/jwt/VCLJwtSignService"; -import VCLJwtDescriptor from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLJwtDescriptor"; -import VCLJwt from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/entities/VCLJwt"; -import VCLJwtVerifyService from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/jwt/VCLJwtVerifyService"; -import { Nullish } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src/api/VCLTypes"; +import VCLCryptoServicesDescriptor from "packages/sdk/src/api/entities/initialization/VCLCryptoServicesDescriptor"; +import { JwtSignServiceMock } from "./mocks/jwt/JwtSignServiceMock"; +import { JwtVerifyServiceMock } from "./mocks/jwt/JwtVerifyServiceMock"; +import { KeyServiceMock } from "./mocks/key/KeyServiceMock"; describe("initalization flow", () => { let appInstance: FastifyInstance; @@ -31,14 +24,14 @@ describe("initalization flow", () => { }); test("App initialization", async () => { - const init = await vcl.initialize( - new VCLInitializationDescriptor(VCLEnvironment.DEV, - new VCLCryptoServicesDescriptor( - new VCLKeyServiceEmptyImpl(), - new VCLJwtSignServiceEmptyImpl(), - new VCLJwtVerifyServiceEmptyImpl() - ) - )); + await vcl.initialize( + new VCLInitializationDescriptor(VCLEnvironment.DEV, + new VCLCryptoServicesDescriptor( + new KeyServiceMock(), + new JwtSignServiceMock(), + new JwtVerifyServiceMock() + ) + )); console.log( "#Credential Types: %s", vcl.credentialTypesModel?.data?.all?.length ?? 0 @@ -83,32 +76,4 @@ describe("initalization flow", () => { afghanistanRegions?.all[2].code == AfghanistanRegion3Code ).toBeTruthy(); }, 400000); -}); - -class VCLKeyServiceEmptyImpl implements VCLKeyService { - generateDidJwk(didJwkDescriptor: VCLDidJwkDescriptor): Promise> { - return new Promise>((resolve, reject) => { - resolve(new VCLResult()); - }); - } -} - -class VCLJwtSignServiceEmptyImpl implements VCLJwtSignService { - sign( - jwtDescriptor: VCLJwtDescriptor, - didJwk: VCLDidJwk, - nonce: Nullish - ): Promise> { - return new Promise>((resolve, reject) => { - resolve(new VCLResult()); - }); - } -} - -class VCLJwtVerifyServiceEmptyImpl implements VCLJwtVerifyService { - verify(jwt: VCLJwt, publicJwk: Nullish): Promise> { - return new Promise>((resolve, reject) => { - resolve(new VCLResult()); - }); - } -} \ No newline at end of file +}); \ No newline at end of file diff --git a/packages/sample-server/test/mocks/DidJwkMocks.ts b/packages/sample-server/test/mocks/DidJwkMocks.ts new file mode 100644 index 0000000..446ef84 --- /dev/null +++ b/packages/sample-server/test/mocks/DidJwkMocks.ts @@ -0,0 +1,20 @@ +import { VCLDidJwk } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk"; + +class DidJwkMocks { + static readonly DidJwkStr = `{ "did": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6InI5ZnlhNTJJbG1UbzN5YlMwd19HZWZlUV9SWDJFSF9ISm1TV3FZWU8ySlkiLCJ5IjoicFFUUmE3R2txYzVrajZvZGVNcXBnVjVUNExqYlphNEY1S1R1MkpEclduYyJ9", "kid": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6InI5ZnlhNTJJbG1UbzN5YlMwd19HZWZlUV9SWDJFSF9ISm1TV3FZWU8ySlkiLCJ5IjoicFFUUmE3R2txYzVrajZvZGVNcXBnVjVUNExqYlphNEY1S1R1MkpEclduYyJ9#0", "keyId": "6630f0a67b097c289711f583", "publicJwk": { "kty": "EC", "crv": "P-256", "y": "pQTRa7Gkqc5kj6odeMqpgV5T4LjbZa4F5KTu2JDrWnc", "x": "r9fya52IlmTo3ybS0w_GefeQ_RX2EH_HJmSWqYYO2JY" } }` + static readonly DidJwkJson = + { + "did": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6InI5ZnlhNTJJbG1UbzN5YlMwd19HZWZlUV9SWDJFSF9ISm1TV3FZWU8ySlkiLCJ5IjoicFFUUmE3R2txYzVrajZvZGVNcXBnVjVUNExqYlphNEY1S1R1MkpEclduYyJ9", + "kid": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6InI5ZnlhNTJJbG1UbzN5YlMwd19HZWZlUV9SWDJFSF9ISm1TV3FZWU8ySlkiLCJ5IjoicFFUUmE3R2txYzVrajZvZGVNcXBnVjVUNExqYlphNEY1S1R1MkpEclduYyJ9#0", + "keyId": "6630f0a67b097c289711f583", + "publicJwk": { + "kty": "EC", + "crv": "P-256", + "y": "pQTRa7Gkqc5kj6odeMqpgV5T4LjbZa4F5KTu2JDrWnc", + "x": "r9fya52IlmTo3ybS0w_GefeQ_RX2EH_HJmSWqYYO2JY" + } + } + static readonly DidJwk = VCLDidJwk.fromJSON(DidJwkMocks.DidJwkJson) +} + +export { DidJwkMocks } \ No newline at end of file diff --git a/packages/sample-server/test/mocks/jwt/JwtSignServiceMock.ts b/packages/sample-server/test/mocks/jwt/JwtSignServiceMock.ts new file mode 100644 index 0000000..21af68d --- /dev/null +++ b/packages/sample-server/test/mocks/jwt/JwtSignServiceMock.ts @@ -0,0 +1,22 @@ +/* eslint-disable unused-imports/no-unused-vars,no-unused-vars */ + +import { + Nullish, + VCLDidJwk, VCLJwt, + VCLJwtDescriptor, + VCLJwtSignService, + VCLToken +} from "@velocitycareerlabs/vnf-nodejs-wallet-sdk"; + +export class JwtSignServiceMock implements VCLJwtSignService { + constructor(readonly successValue: Nullish = null) {} + + async sign( + jwtDescriptor: VCLJwtDescriptor, + didJwk: VCLDidJwk, + nonce: Nullish, + remoteCryptoServicesToken: Nullish + ): Promise { + return VCLJwt.fromEncodedJwt(this.successValue || ''); + } +} \ No newline at end of file diff --git a/packages/sample-server/test/mocks/jwt/JwtVerifyServiceMock.ts b/packages/sample-server/test/mocks/jwt/JwtVerifyServiceMock.ts new file mode 100644 index 0000000..ed53fff --- /dev/null +++ b/packages/sample-server/test/mocks/jwt/JwtVerifyServiceMock.ts @@ -0,0 +1,9 @@ +/* eslint-disable unused-imports/no-unused-vars,no-unused-vars */ + +import { Nullish, VCLJwt, VCLJwtVerifyService, VCLPublicJwk } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk"; + +export class JwtVerifyServiceMock implements VCLJwtVerifyService { + async verify(jwt: VCLJwt, publicJwk: Nullish): Promise { + return true; + } +} \ No newline at end of file diff --git a/packages/sample-server/test/mocks/key/KeyServiceMock.ts b/packages/sample-server/test/mocks/key/KeyServiceMock.ts new file mode 100644 index 0000000..2b30921 --- /dev/null +++ b/packages/sample-server/test/mocks/key/KeyServiceMock.ts @@ -0,0 +1,10 @@ +/* eslint-disable unused-imports/no-unused-vars,no-unused-vars */ + +import { VCLDidJwk, VCLDidJwkDescriptor, VCLKeyService } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk"; +import { DidJwkMocks } from "../DidJwkMocks"; + +export class KeyServiceMock implements VCLKeyService { + async generateDidJwk(didJwkDescriptor: VCLDidJwkDescriptor): Promise { + return DidJwkMocks.DidJwk + } +} \ No newline at end of file diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 583bcab..7070622 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,12 +1,12 @@ { "name": "@velocitycareerlabs/vnf-nodejs-wallet-sdk", - "version": "0.8.35", + "version": "0.9.0", "description": "VNF Wallet SDK Nodejs", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { - "lint": "eslint .", - "lint:fix": "eslint --fix --ext .js .", + "lint": "eslint . --ext .js,.ts,.tsx", + "lint:fix": "eslint --fix --ext .js,.ts,.tsx .", "prepublish": "tsc --declaration", "build": "tsc", "test": "jest", @@ -31,15 +31,14 @@ "@typescript-eslint/eslint-plugin": "~5.57.0", "@typescript-eslint/parser": "~5.57.0", "eslint": "~8.57.0", - "eslint-config-prettier": "~8.8.0", + "eslint-config-prettier": "~9.1.0", "eslint-plugin-prettier": "~4.2.1", "eslint-plugin-autofix": "^1.0.0", "eslint-plugin-better-mutation": "1.4.0", "eslint-plugin-import": "^2.22.0", "eslint-plugin-prefer-arrow-functions": "^3.0.1", - "eslint-plugin-unused-imports": "^3.2.0", + "eslint-plugin-unused-imports": "^4.0.0", "jest": "~29.5.0", - "prettier": "~2.8.7", "rimraf": "~4.4.1", "rollup": "~3.20.2", "ts-jest": "~29.0.5", diff --git a/packages/sdk/src/api/VCL.ts b/packages/sdk/src/api/VCL.ts index 19d5fe4..c0c3541 100644 --- a/packages/sdk/src/api/VCL.ts +++ b/packages/sdk/src/api/VCL.ts @@ -1,8 +1,5 @@ -import VCLCountries from "./entities/VCLCountries"; import VCLCredentialManifest from "./entities/VCLCredentialManifest"; import VCLCredentialManifestDescriptor from "./entities/VCLCredentialManifestDescriptor"; -import VCLCredentialTypeSchemas from "./entities/VCLCredentialTypeSchemas"; -import VCLCredentialTypes from "./entities/VCLCredentialTypes"; import VCLCredentialTypesUIFormSchema from "./entities/VCLCredentialTypesUIFormSchema"; import VCLCredentialTypesUIFormSchemaDescriptor from "./entities/VCLCredentialTypesUIFormSchemaDescriptor"; import VCLDidJwk from "./entities/VCLDidJwk"; @@ -11,7 +8,7 @@ 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 VCLInitializationDescriptor from "./entities/initialization/VCLInitializationDescriptor"; import VCLPublicJwk from "./entities/VCLPublicJwk"; import VCLJwt from "./entities/VCLJwt"; import VCLJwtDescriptor from "./entities/VCLJwtDescriptor"; @@ -27,7 +24,6 @@ import VCLToken from "./entities/VCLToken"; import VCLVerifiedProfile from "./entities/VCLVerifiedProfile"; import VCLVerifiedProfileDescriptor from "./entities/VCLVerifiedProfileDescriptor"; import { Nullish } from "./VCLTypes"; -import VCLResult from "./entities/VCLResult"; export default interface VCL { initialize( @@ -60,12 +56,12 @@ export default interface VCL { checkForOffers( generateOffersDescriptor: VCLGenerateOffersDescriptor, - token: VCLToken + sessionToken: VCLToken, ): Promise; finalizeOffers( finalizeOffersDescriptor: VCLFinalizeOffersDescriptor, - token: VCLToken + sessionToken: VCLToken, ): Promise; getCredentialTypesUIFormSchema( diff --git a/packages/sdk/src/api/entities/VCLCredentialManifest.ts b/packages/sdk/src/api/entities/VCLCredentialManifest.ts index da22341..7b8d58e 100644 --- a/packages/sdk/src/api/entities/VCLCredentialManifest.ts +++ b/packages/sdk/src/api/entities/VCLCredentialManifest.ts @@ -23,6 +23,29 @@ export default class VCLCredentialManifest { return this.iss; } + get aud(): string { return this.retrieveAud() } + + get issuerId(): string { + const payload = this.jwt.payload; + + if (!payload) { + return ""; + } + + const issuer = payload[VCLCredentialManifest.KeyIssuer]; + + if (typeof issuer === 'string') { + return issuer; + } + + const issuerMap = payload[VCLCredentialManifest.KeyIssuer] as Record | undefined; + const issuerId = issuerMap?.[VCLCredentialManifest.KeyId] as string | undefined; + + return issuerId ?? ""; + } + + + get exchangeId(): string { return this.jwt.payload[VCLCredentialManifest.KeyExchangeId] ?? ""; } @@ -59,6 +82,13 @@ export default class VCLCredentialManifest { ); } + private retrieveAud(): string { + const keyMetadata = this.jwt.payload[VCLCredentialManifest.KeyMetadata] ?? {}; + const finalizeOffersUri = (keyMetadata as Record)[VCLCredentialManifest.KeyFinalizeOffersUri] ?? ""; + return finalizeOffersUri.split("/issue/")[0]; + } + + // CodingKeys static readonly KeyIssuingRequest: string = "issuing_request"; static readonly KeyId: string = "id"; diff --git a/packages/sdk/src/api/entities/VCLCredentialType.ts b/packages/sdk/src/api/entities/VCLCredentialType.ts index ed31af1..6cb2126 100644 --- a/packages/sdk/src/api/entities/VCLCredentialType.ts +++ b/packages/sdk/src/api/entities/VCLCredentialType.ts @@ -3,12 +3,12 @@ import { Dictionary, Nullish } from "../VCLTypes"; export default class VCLCredentialType { constructor( public payload: Dictionary, - public id: Nullish, - public schema: Nullish, - public createdAt: Nullish, - public schemaName: Nullish, - public credentialType: Nullish, - public recommended: boolean + public id: Nullish = null, + public schema: Nullish = null, + public createdAt: Nullish = null, + public schemaName: Nullish = null, + public credentialType: Nullish = null, + public recommended: boolean = false ) {} // CodingKeys diff --git a/packages/sdk/src/api/entities/VCLDidJwk.ts b/packages/sdk/src/api/entities/VCLDidJwk.ts index 4b934b4..7f3cc29 100644 --- a/packages/sdk/src/api/entities/VCLDidJwk.ts +++ b/packages/sdk/src/api/entities/VCLDidJwk.ts @@ -1,6 +1,6 @@ -import { JWK, base64url, exportJWK } from "jose"; +import { base64url, exportJWK } from "jose"; import VCLPublicJwk from "./VCLPublicJwk"; -import { KeyObject, KeyPairKeyObjectResult } from "crypto"; +import { KeyPairKeyObjectResult } from "crypto"; import canonicalize from "canonicalize"; import { Dictionary } from "../VCLTypes"; diff --git a/packages/sdk/src/api/entities/VCLExchangeDescriptor.ts b/packages/sdk/src/api/entities/VCLExchangeDescriptor.ts index aeda687..0f8c93e 100644 --- a/packages/sdk/src/api/entities/VCLExchangeDescriptor.ts +++ b/packages/sdk/src/api/entities/VCLExchangeDescriptor.ts @@ -11,10 +11,6 @@ export default class VCLExchangeDescriptor { return this.presentationSubmission.progressUri; } - get did() { - return this.presentationSubmission.iss; - } - get exchangeId() { return this.submissionResult.exchange.id; } diff --git a/packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts b/packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts index 2ab95a1..49960fa 100644 --- a/packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts +++ b/packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts @@ -1,13 +1,16 @@ import { Dictionary } from "../VCLTypes"; import VCLCredentialManifest from "./VCLCredentialManifest"; import VCLJwt from "./VCLJwt"; +import VCLOffers from "./VCLOffers"; export default class VCLFinalizeOffersDescriptor { constructor( public readonly credentialManifest: VCLCredentialManifest, + public readonly offers: VCLOffers, public readonly approvedOfferIds: string[], public readonly rejectedOfferIds: string[] - ) {} + ) { + } get exchangeId() { return this.credentialManifest.exchangeId; @@ -23,10 +26,8 @@ export default class VCLFinalizeOffersDescriptor { payload: Dictionary = { [VCLFinalizeOffersDescriptor.KeyExchangeId]: this.exchangeId, - [VCLFinalizeOffersDescriptor.KeyApprovedOfferIds]: - this.approvedOfferIds, - [VCLFinalizeOffersDescriptor.KeyRejectedOfferIds]: - this.rejectedOfferIds, + [VCLFinalizeOffersDescriptor.KeyApprovedOfferIds]: this.approvedOfferIds, + [VCLFinalizeOffersDescriptor.KeyRejectedOfferIds]: this.rejectedOfferIds, }; generateRequestBody(jwt: VCLJwt): Dictionary { diff --git a/packages/sdk/src/api/entities/VCLIdentificationSubmission.ts b/packages/sdk/src/api/entities/VCLIdentificationSubmission.ts index 22075d7..34388bf 100644 --- a/packages/sdk/src/api/entities/VCLIdentificationSubmission.ts +++ b/packages/sdk/src/api/entities/VCLIdentificationSubmission.ts @@ -1,9 +1,6 @@ import VCLCredentialManifest from "./VCLCredentialManifest"; import VCLSubmission from "./VCLSubmission"; import VCLVerifiableCredential from "./VCLVerifiableCredential"; -import { Nullish } from "../VCLTypes"; -import VCLToken from "./VCLToken"; -import VCLPushDelegate from "./VCLPushDelegate"; export default class VCLIdentificationSubmission extends VCLSubmission { constructor( @@ -12,7 +9,6 @@ export default class VCLIdentificationSubmission extends VCLSubmission { ) { super( credentialManifest.submitPresentationUri, - credentialManifest.iss, credentialManifest.exchangeId, credentialManifest.presentationDefinitionId, verifiableCredentials, diff --git a/packages/sdk/src/api/entities/VCLPresentationSubmission.ts b/packages/sdk/src/api/entities/VCLPresentationSubmission.ts index 1899130..83f38b1 100644 --- a/packages/sdk/src/api/entities/VCLPresentationSubmission.ts +++ b/packages/sdk/src/api/entities/VCLPresentationSubmission.ts @@ -10,7 +10,6 @@ export default class VCLPresentationSubmission extends VCLSubmission { ) { super( presentationRequest.submitPresentationUri, - presentationRequest.iss, presentationRequest.exchangeId, presentationRequest.presentationDefinitionId, verifiableCredentials, @@ -19,7 +18,6 @@ export default class VCLPresentationSubmission extends VCLSubmission { presentationRequest.didJwk, presentationRequest.remoteCryptoServicesToken ); - this.progressUri = presentationRequest.progressUri; } } diff --git a/packages/sdk/src/api/entities/VCLResult.ts b/packages/sdk/src/api/entities/VCLResult.ts deleted file mode 100644 index efab544..0000000 --- a/packages/sdk/src/api/entities/VCLResult.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Nullish } from "../VCLTypes"; -import VCLError from "./error/VCLError"; - -export default class VCLResult { - static Success = class extends VCLResult { - constructor(public data: T) { - super(); - } - - handleResult(): [Nullish, Nullish] { - return [null, this.data]; - } - - getData(): Nullish { - return this.data; - } - }; - - static Error = class extends VCLResult { - constructor(public error: VCLError) { - super(); - } - handleResult(): [Nullish, Nullish] { - return [this.error, null]; - } - }; - - handleResult(): [Nullish, Nullish] { - return [null, null]; - } - - getData(): Nullish { - return undefined; - } -} diff --git a/packages/sdk/src/api/entities/VCLSubmission.ts b/packages/sdk/src/api/entities/VCLSubmission.ts index 4aa7873..e5f29ab 100644 --- a/packages/sdk/src/api/entities/VCLSubmission.ts +++ b/packages/sdk/src/api/entities/VCLSubmission.ts @@ -9,7 +9,6 @@ import VCLDidJwk from "./VCLDidJwk"; export default class VCLSubmission { constructor( public readonly submitUri: string, - public readonly iss: string, public readonly exchangeId: string, public readonly presentationDefinitionId: string, public readonly verifiableCredentials: VCLVerifiableCredential[], @@ -23,12 +22,10 @@ export default class VCLSubmission { readonly jti = crypto.randomUUID().toString(); readonly submissionId = crypto.randomUUID().toString(); - get payload() { - return this.generatePayload(); - } - public generatePayload(iss?: string) { + public generatePayload(iss: Nullish = null) { const result: Dictionary = { [VCLSubmission.KeyJti]: this.jti, + [VCLSubmission.KeyIss]: iss, [VCLSubmission.KeyVp]: { [VCLSubmission.KeyType]: VCLSubmission.ValueVerifiablePresentation, @@ -70,6 +67,7 @@ export default class VCLSubmission { } static readonly KeyJti = "jti"; + static readonly KeyIss = "iss" static readonly KeyId = "id"; static readonly KeyVp = "vp"; static readonly KeyDid = "did"; diff --git a/packages/sdk/src/api/entities/VCLVerifiedProfile.ts b/packages/sdk/src/api/entities/VCLVerifiedProfile.ts index 06e3e3c..62e4d9f 100644 --- a/packages/sdk/src/api/entities/VCLVerifiedProfile.ts +++ b/packages/sdk/src/api/entities/VCLVerifiedProfile.ts @@ -1,9 +1,22 @@ import { Dictionary, Nullish } from "../VCLTypes"; -import VCLServiceType, { serviceTypeFromString } from "./VCLServiceType"; +import VCLServiceType from "./VCLServiceType"; import VCLServiceTypes from "./VCLServiceTypes"; export default class VCLVerifiedProfile { - constructor(public readonly payload: Dictionary) {} + public credentialSubject: Nullish>; + public name: Nullish; + public logo: Nullish; + public id: Nullish; + public serviceTypes: VCLServiceTypes; + constructor(public readonly payload: Dictionary) { + this.credentialSubject = this.payload[VCLVerifiedProfile.KeyCredentialSubject]; + this.name = (this.credentialSubject ? this.credentialSubject[VCLVerifiedProfile.KeyName] : null); + this.logo = (this.credentialSubject ? this.credentialSubject[VCLVerifiedProfile.KeyLogo] : null); + this.id = (this.credentialSubject ? this.credentialSubject[VCLVerifiedProfile.KeyId] : null); + this.serviceTypes = this.retrieveServiceTypes( + (this.credentialSubject ? this.credentialSubject[VCLVerifiedProfile.KeyServiceType] : []) + ); + } retrieveServiceTypes(serviceCategoriesJsonArr: any[]) { const result: VCLServiceType[] = []; @@ -19,28 +32,6 @@ export default class VCLVerifiedProfile { return new VCLServiceTypes(result); } - get credentialSubject(): Nullish> { - return this.payload[VCLVerifiedProfile.KeyCredentialSubject]; - } - - get name(): Nullish { - return this.payload[VCLVerifiedProfile.KeyName]; - } - - get logo(): Nullish { - return this.payload[VCLVerifiedProfile.KeyLogo]; - } - - get id(): Nullish { - return this.payload[VCLVerifiedProfile.KeyId]; - } - - get serviceTypes() { - return this.retrieveServiceTypes( - (this.credentialSubject ? this.credentialSubject[VCLVerifiedProfile.KeyServiceType] : []) - ); - } - static readonly KeyCredentialSubject = "credentialSubject"; static readonly KeyName = "name"; static readonly KeyLogo = "logo"; diff --git a/packages/sdk/src/api/entities/error/VCLError.ts b/packages/sdk/src/api/entities/error/VCLError.ts index 2e974f1..62219ed 100644 --- a/packages/sdk/src/api/entities/error/VCLError.ts +++ b/packages/sdk/src/api/entities/error/VCLError.ts @@ -1,17 +1,18 @@ import { Dictionary, Nullish } from "../../VCLTypes"; import VCLErrorCode from "./VCLErrorCode"; +import VCLStatusCode from "./VCLStatusCode"; export default class VCLError extends Error { payload: Nullish = null; error: Nullish = null; errorCode: string = VCLErrorCode.SdkError.toString(); - statusCode: Nullish = null; + statusCode: Nullish = null; constructor( error: Nullish = null, errorCode: string = VCLErrorCode.SdkError.toString(), message: Nullish = null, - statusCode: Nullish = null + statusCode: Nullish = null ) { super(message ?? ""); this.error = error; @@ -39,13 +40,12 @@ export default class VCLError extends Error { exception: Error, statusCode: number | null = null ): VCLError { - const result = new VCLError( - null, - VCLErrorCode.SdkError.toString(), - exception.message, + return new VCLError( + null, + VCLErrorCode.SdkError.toString(), + exception.message, statusCode - ); - return result; + ); } get jsonObject(): Dictionary { diff --git a/packages/sdk/src/api/entities/VCLCryptoServicesDescriptor.ts b/packages/sdk/src/api/entities/initialization/VCLCryptoServicesDescriptor.ts similarity index 58% rename from packages/sdk/src/api/entities/VCLCryptoServicesDescriptor.ts rename to packages/sdk/src/api/entities/initialization/VCLCryptoServicesDescriptor.ts index 68854b3..5d9f5e9 100644 --- a/packages/sdk/src/api/entities/VCLCryptoServicesDescriptor.ts +++ b/packages/sdk/src/api/entities/initialization/VCLCryptoServicesDescriptor.ts @@ -1,6 +1,6 @@ -import VCLJwtSignService from "../jwt/VCLJwtSignService"; -import VCLJwtVerifyService from "../jwt/VCLJwtVerifyService"; -import VCLKeyService from "../keys/VCLKeyService"; +import VCLJwtSignService from "../../jwt/VCLJwtSignService"; +import VCLJwtVerifyService from "../../jwt/VCLJwtVerifyService"; +import VCLKeyService from "../../keys/VCLKeyService"; export default class VCLCryptoServicesDescriptor { constructor( diff --git a/packages/sdk/src/api/entities/VCLInitializationDescriptor.ts b/packages/sdk/src/api/entities/initialization/VCLInitializationDescriptor.ts similarity index 85% rename from packages/sdk/src/api/entities/VCLInitializationDescriptor.ts rename to packages/sdk/src/api/entities/initialization/VCLInitializationDescriptor.ts index 3f965e6..79a4f65 100644 --- a/packages/sdk/src/api/entities/VCLInitializationDescriptor.ts +++ b/packages/sdk/src/api/entities/initialization/VCLInitializationDescriptor.ts @@ -1,4 +1,4 @@ -import VCLEnvironment from "../VCLEnvironment"; +import VCLEnvironment from "../../VCLEnvironment"; import VCLCryptoServicesDescriptor from "./VCLCryptoServicesDescriptor"; export default class VCLInitializationDescriptor { diff --git a/packages/sdk/src/api/jwt/VCLJwtSignService.ts b/packages/sdk/src/api/jwt/VCLJwtSignService.ts index 73fa2c6..c56a914 100644 --- a/packages/sdk/src/api/jwt/VCLJwtSignService.ts +++ b/packages/sdk/src/api/jwt/VCLJwtSignService.ts @@ -1,19 +1,7 @@ -/* -interface VCLJwtSignService { - fun sign( - kid: String? = null, - nonce: String? = null, - jwtDescriptor: VCLJwtDescriptor, - remoteCryptoServicesToken: VCLToken? = null, - completionBlock: (VCLResult) -> Unit - ) -}*/ - import { Nullish } from "../VCLTypes"; import VCLDidJwk from "../entities/VCLDidJwk"; import VCLJwt from "../entities/VCLJwt"; import VCLJwtDescriptor from "../entities/VCLJwtDescriptor"; -import VCLResult from "../entities/VCLResult"; import VCLToken from "../entities/VCLToken"; export default interface VCLJwtSignService { @@ -22,5 +10,5 @@ export default interface VCLJwtSignService { didJwk: VCLDidJwk, nonce: Nullish, remoteCryptoServicesToken: Nullish - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/api/jwt/VCLJwtVerifyService.ts b/packages/sdk/src/api/jwt/VCLJwtVerifyService.ts index 3c13a53..3665854 100644 --- a/packages/sdk/src/api/jwt/VCLJwtVerifyService.ts +++ b/packages/sdk/src/api/jwt/VCLJwtVerifyService.ts @@ -1,6 +1,5 @@ import VCLJwt from "../entities/VCLJwt"; import VCLPublicJwk from "../entities/VCLPublicJwk"; -import VCLResult from "../entities/VCLResult"; import { Nullish } from "../VCLTypes"; import VCLToken from "../entities/VCLToken"; @@ -9,5 +8,5 @@ export default interface VCLJwtVerifyService { jwt: VCLJwt, publicJwk: Nullish, remoteCryptoServicesToken: Nullish - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/api/keys/VCLKeyService.ts b/packages/sdk/src/api/keys/VCLKeyService.ts index e919248..2dcbc6c 100644 --- a/packages/sdk/src/api/keys/VCLKeyService.ts +++ b/packages/sdk/src/api/keys/VCLKeyService.ts @@ -1,11 +1,8 @@ -// Assuming similar entity structures and imports for Node.js environment - import VCLDidJwk from "../entities/VCLDidJwk"; -import VCLResult from "../entities/VCLResult"; import VCLDidJwkDescriptor from "../entities/VCLDidJwkDescriptor"; export default interface VCLKeyService { generateDidJwk( didJwkDescriptor: VCLDidJwkDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/global.ts b/packages/sdk/src/global.ts index 0f8e4a4..94f74c5 100644 --- a/packages/sdk/src/global.ts +++ b/packages/sdk/src/global.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars interface String { getQueryParameters(): Map; appendQueryParams(queryParams: string): string; @@ -5,10 +6,12 @@ interface String { randomString(length: number): string; } +// eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars interface Array { toJsonArray(): any[]; } +// eslint-disable-next-line unused-imports/no-unused-vars interface Date { addDaysToNow(days: number): Date; equalsTo(date: Date): boolean; diff --git a/packages/sdk/src/impl/VCLImpl.ts b/packages/sdk/src/impl/VCLImpl.ts index 6e7f5b8..1ed95f1 100644 --- a/packages/sdk/src/impl/VCLImpl.ts +++ b/packages/sdk/src/impl/VCLImpl.ts @@ -1,28 +1,19 @@ import VCL from "../api/VCL"; -import VCLEnvironment from "../api/VCLEnvironment"; -import VCLCountries from "../api/entities/VCLCountries"; -import VCLCredentialManifest from "../api/entities/VCLCredentialManifest"; import VCLCredentialManifestDescriptor from "../api/entities/VCLCredentialManifestDescriptor"; -import VCLCredentialTypeSchemas from "../api/entities/VCLCredentialTypeSchemas"; -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/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 VCLInitializationDescriptor from "../api/entities/initialization/VCLInitializationDescriptor"; import VCLPublicJwk from "../api/entities/VCLPublicJwk"; import VCLJwt from "../api/entities/VCLJwt"; import VCLJwtDescriptor from "../api/entities/VCLJwtDescriptor"; -import VCLJwtVerifiableCredentials from "../api/entities/VCLJwtVerifiableCredentials"; import VCLOffers from "../api/entities/VCLOffers"; -import VCLOrganizations from "../api/entities/VCLOrganizations"; import VCLOrganizationsSearchDescriptor from "../api/entities/VCLOrganizationsSearchDescriptor"; -import VCLPresentationRequest from "../api/entities/VCLPresentationRequest"; import VCLPresentationRequestDescriptor from "../api/entities/VCLPresentationRequestDescriptor"; import VCLPresentationSubmission from "../api/entities/VCLPresentationSubmission"; import VCLServiceType from "../api/entities/VCLServiceType"; @@ -38,12 +29,10 @@ import CredentialTypeSchemasModel from "./domain/models/CredentialTypeSchemasMod import CredentialTypesModel from "./domain/models/CredentialTypesModel"; import InitializationWatcher from "./utils/InitializationWatcher"; import { ProfileServiceTypeVerifier } from "./utils/ProfileServiceTypeVerifier"; -import PromiseConverter from "./utils/PromiseConverter"; import VCLLog from "./utils/VCLLog"; import "./extensions/DateExtensions"; import "./extensions/StringExtensions"; import "./extensions/ListExtensions"; -import VCLResult from "../api/entities/VCLResult"; import VCLErrorCode from "../api/entities/error/VCLErrorCode"; import VerifiedProfileUseCase from "./domain/usecases/VerifiedProfileUseCase"; import JwtServiceUseCase from "./domain/usecases/JwtServiceUseCase"; @@ -148,6 +137,7 @@ export class VCLImpl implements VCL { VclBlocksProvider.provideCredentialTypeSchemasModel( credentialTypes ); + // eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars const initializeCredentialTypeSchemasError = await this.credentialTypeSchemasModel.initialize(); @@ -228,93 +218,57 @@ export class VCLImpl implements VCL { logError("getPresentationRequest::verifiedProfile", err); throw err; } - - const verifiedProfileResult = - await this.profileServiceTypeVerifier.verifyServiceTypeOfVerifiedProfile( - new VCLVerifiedProfileDescriptor(did), - new VCLServiceTypes([VCLServiceType.Inspector]) - ); - - const [error1, verifiedProfile] = - verifiedProfileResult.handleResult(); - if (error1) { - console.log(error1); - // logError("getPresentationRequest", error); - logError("profile verification failed", error1); - throw error1; - } - - let presentationRequestResult: Nullish< - VCLResult - >; - try { - presentationRequestResult = - await this.presentationRequestUseCase.getPresentationRequest( - presentationRequestDescriptor, - verifiedProfile + const verifiedProfile = + await this.profileServiceTypeVerifier.verifyServiceTypeOfVerifiedProfile( + new VCLVerifiedProfileDescriptor(did), + new VCLServiceTypes([VCLServiceType.Inspector]) ); + return await this.presentationRequestUseCase.getPresentationRequest( + presentationRequestDescriptor, + verifiedProfile + ); } catch (error: any) { logError("getPresentationRequest", error); throw error; } - - const [error2, presentationRequest] = - presentationRequestResult.handleResult(); - - if (error2) { - throw error2; - } - return presentationRequest!; }; submitPresentation = async ( presentationSubmission: VCLPresentationSubmission ) => { - const presentationSubmissionSubmission = - await this.presentationSubmissionUseCase.submit( - presentationSubmission - ); - const [error, presentationSubmissionResult] = - presentationSubmissionSubmission.handleResult(); - - if (error) { + try { + return await this.presentationSubmissionUseCase.submit( + presentationSubmission + ); + } catch(error: any) { logError("submit presentation", error); throw error; } - return presentationSubmissionResult!; }; getExchangeProgress = async (exchangeDescriptor: VCLExchangeDescriptor) => { - const exchangeProgressResult = - await this.exchangeProgressUseCase.getExchangeProgress( + try { + return await this.exchangeProgressUseCase.getExchangeProgress( exchangeDescriptor ); - - const [error, exchangeProgress] = - exchangeProgressResult.handleResult(); - if (error) { + } catch (error: any) { logError("getExchangeProgress", error); throw error; } - - return exchangeProgress!; }; searchForOrganizations = async ( organizationsSearchDescriptor: VCLOrganizationsSearchDescriptor ) => { - const organization = - await this.organizationsUseCase.searchForOrganizations( + try { + return await this.organizationsUseCase.searchForOrganizations( organizationsSearchDescriptor ); - const [error, organizationResult] = organization.handleResult(); - if (error) { - logError("searchForOrganizations", error); + } catch (error: any) { + logError("getExchangeProgress", error); throw error; } - - return organizationResult!; }; getCredentialManifest = async ( @@ -329,44 +283,33 @@ export class VCLImpl implements VCL { VCLErrorCode.SdkError.toString(), null ); - VCLLog.e( - VCLImpl.TAG, - "getCredentialManifest.verifiedProfile" + - JSON.stringify(error.jsonObject) - ); + logError('', error); throw error; } + let verifiedProfile: VCLVerifiedProfile; try { - const verifiedProfileResult = + verifiedProfile = await this.profileServiceTypeVerifier.verifyServiceTypeOfVerifiedProfile( new VCLVerifiedProfileDescriptor(did), VCLServiceTypes.fromIssuingType( credentialManifestDescriptor.issuingType ) ); - - const [err, verifiedProfile] = verifiedProfileResult.handleResult(); - if (verifiedProfile) { - const credentialManifest = - await this.credentialManifestUseCase.getCredentialManifest( - credentialManifestDescriptor, - verifiedProfile - ); - const [error, credentialManifestResult] = - credentialManifest.handleResult(); - if (error) { - logError("getCredentialManifest", error); - throw error; - } - return credentialManifestResult!; - } else { - throw err; - } } catch (error: any) { - logError("profile verification failed", error); + logError(`failed to find verified profile by did ${did}`, error); + throw error; + } + try { + return await this.credentialManifestUseCase.getCredentialManifest( + credentialManifestDescriptor, + verifiedProfile + ); + } catch (error: any) { + logError("getCredentialManifest", error); throw error; } }; + generateOffers = async ( generateOffersDescriptor: VCLGenerateOffersDescriptor, ) => { @@ -374,52 +317,48 @@ export class VCLImpl implements VCL { generateOffersDescriptor.credentialManifest, generateOffersDescriptor.identificationVerifiableCredentials ); - - const identificationSubmissionResult = - await this.identificationUseCase.submit( - identificationSubmission, - ); - - const [error, submission] = identificationSubmissionResult.handleResult(); - if (error) { + let identificationSubmissionResult: VCLSubmissionResult; + try { + identificationSubmissionResult = + await this.identificationUseCase.submit( + identificationSubmission, + ); + } catch (error: any) { logError("submit identification", error); throw error; } - console.log("Identification submitted success."); - console.log(submission); + VCLLog.i(VCLImpl.TAG, "Identification submitted success."); return this.invokeGenerateOffersUseCase( generateOffersDescriptor, - submission!.sessionToken + identificationSubmissionResult.sessionToken ); }; checkForOffers( generateOffersDescriptor: VCLGenerateOffersDescriptor, - token: VCLToken + sessionToken: VCLToken, ): Promise { return this.invokeGenerateOffersUseCase( generateOffersDescriptor, - token + sessionToken ); } + finalizeOffers = async ( finalizeOffersDescriptor: VCLFinalizeOffersDescriptor, - token: VCLToken + sessionToken: VCLToken, ) => { - const jwtVerifiableCredentials = - await this.finalizeOffersUseCase.finalizeOffers( - token, - finalizeOffersDescriptor + try { + return await this.finalizeOffersUseCase.finalizeOffers( + finalizeOffersDescriptor, + sessionToken ); - - const [error, result] = jwtVerifiableCredentials.handleResult(); - if (error) { + } catch (error: any) { logError("finalizeOffers", error); throw error; } - return result!; }; async getCredentialTypesUIFormSchema( @@ -427,19 +366,15 @@ export class VCLImpl implements VCL { ): Promise { const countries = this.countriesModel?.data; if (countries) { - const credentialTypesUIFormSchemaResult = - await this.credentialTypesUIFormSchemaUseCase.getCredentialTypesUIFormSchema( + try { + return await this.credentialTypesUIFormSchemaUseCase.getCredentialTypesUIFormSchema( credentialTypesUIFormSchemaDescriptor, countries ); - - const [err, result] = - credentialTypesUIFormSchemaResult.handleResult(); - if (err) { - throw err; + } catch (error: any) { + logError("getCredentialTypesUIFormSchema", error); + throw error; } - - return result!; } else { const error = new VCLError( "No countries for getCredentialTypesUIFormSchema" @@ -452,16 +387,14 @@ export class VCLImpl implements VCL { getVerifiedProfile = async ( verifiedProfileDescriptor: VCLVerifiedProfileDescriptor ): Promise => { - const verifiedProfileResult = - await this.verifiedProfileUseCase.getVerifiedProfile( - verifiedProfileDescriptor - ); - const [error, result] = verifiedProfileResult.handleResult(); - if (error) { + try { + return await this.verifiedProfileUseCase.getVerifiedProfile( + verifiedProfileDescriptor + ); + } catch (error: any) { logError("getVerifiedProfile", error); throw error; } - return result!; }; verifyJwt = async ( @@ -469,18 +402,16 @@ export class VCLImpl implements VCL { publicJwk: Nullish, remoteCryptoServicesToken: Nullish ) => { - const isVerifiedResult = await this.jwtServiceUseCase.verifyJwt( - jwt, - publicJwk, - remoteCryptoServicesToken - ); - - const [err, result] = isVerifiedResult.handleResult(); - if (err) { - logError("verifyJwt", err); - throw err; + try { + return await this.jwtServiceUseCase.verifyJwt( + jwt, + publicJwk, + remoteCryptoServicesToken + ); + } catch (error: any) { + logError("verifyJwt", error); + throw error; } - return result!; }; generateSignedJwt = async ( @@ -489,52 +420,47 @@ export class VCLImpl implements VCL { nonce: Nullish, remoteCryptoServicesToken: Nullish ) => { - const jwtResult = await this.jwtServiceUseCase.generateSignedJwt( - jwtDescriptor, - didJwk, - nonce, - remoteCryptoServicesToken - ); - - const [err, result] = jwtResult.handleResult(); - if (err) { - logError("generateSignedJwt", err); - throw err; + try { + return await this.jwtServiceUseCase.generateSignedJwt( + jwtDescriptor, + didJwk, + nonce, + remoteCryptoServicesToken + ); + } catch (error: any) { + logError("generateSignedJwt", error); + throw error; } - return result!; }; generateDidJwk = async (didJwkDescriptor: VCLDidJwkDescriptor) => { - const didJwkResult = await this.keyServiceUseCase.generateDidJwk( - didJwkDescriptor - ); - - const [err, result] = didJwkResult.handleResult(); - if (err) { - throw err; + try { + return await this.keyServiceUseCase.generateDidJwk( + didJwkDescriptor + ); + } catch (error: any) { + logError("generateDidJwk", error); + throw error; } - return result!; }; printVersion(): void { - throw new Error("Method not implemented."); + VCLLog.e('', "Method not implemented."); } private async invokeGenerateOffersUseCase( generateOffersDescriptor: VCLGenerateOffersDescriptor, - token: VCLToken + sessionToken: VCLToken ): Promise { - const vnOffersResult = await this.generateOffersUseCase.generateOffers( - token, - generateOffersDescriptor - ); - - const [err, result] = vnOffersResult.handleResult(); - - if (err) { - throw err; + try { + return await this.generateOffersUseCase.generateOffers( + generateOffersDescriptor, + sessionToken + ); + } catch (error: any) { + logError("generateOffers", error); + throw error; } - return result!; } } diff --git a/packages/sdk/src/impl/VclBlocksProvider.ts b/packages/sdk/src/impl/VclBlocksProvider.ts index bad3e9e..d9bf19e 100644 --- a/packages/sdk/src/impl/VclBlocksProvider.ts +++ b/packages/sdk/src/impl/VclBlocksProvider.ts @@ -1,10 +1,7 @@ import VCLCredentialTypes from "../api/entities/VCLCredentialTypes"; -import VCLCryptoServicesDescriptor from "../api/entities/VCLCryptoServicesDescriptor"; -import VCLError from "../api/entities/error/VCLError"; -import VCLErrorCode from "../api/entities/VCLErrorCode"; +import VCLCryptoServicesDescriptor from "../api/entities/initialization/VCLCryptoServicesDescriptor"; import VCLJwtSignService from "../api/jwt/VCLJwtSignService"; import VCLJwtVerifyService from "../api/jwt/VCLJwtVerifyService"; -import VCLKeyService from "../api/keys/VCLKeyService"; import NetworkServiceImpl from "./data/infrastructure/network/NetworkServiceImpl"; import CountriesModelImpl from "./data/models/CountriesModelImpl"; import CredentialTypeSchemasModelImpl from "./data/models/CredentialTypeSchemasModelImpl"; diff --git a/packages/sdk/src/impl/data/infrastructure/jwt/JwtServiceImpl.ts b/packages/sdk/src/impl/data/infrastructure/jwt/JwtServiceImpl.ts index b1b4006..fdd8f55 100644 --- a/packages/sdk/src/impl/data/infrastructure/jwt/JwtServiceImpl.ts +++ b/packages/sdk/src/impl/data/infrastructure/jwt/JwtServiceImpl.ts @@ -1,5 +1,5 @@ +/* eslint-disable */ import { jwtVerify, base64url, JWK, exportJWK, SignJWT, importJWK } from "jose"; - import util from "util"; import VCLDidJwk from "../../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../../api/entities/VCLDidJwkDescriptor"; diff --git a/packages/sdk/src/impl/data/infrastructure/network/NetworkServiceImpl.ts b/packages/sdk/src/impl/data/infrastructure/network/NetworkServiceImpl.ts index 68fb1b3..5d5532d 100644 --- a/packages/sdk/src/impl/data/infrastructure/network/NetworkServiceImpl.ts +++ b/packages/sdk/src/impl/data/infrastructure/network/NetworkServiceImpl.ts @@ -1,5 +1,4 @@ import { Nullish } from "../../../../api/VCLTypes"; -import VCLResult from "../../../../api/entities/VCLResult"; import NetworkService from "../../../domain/infrastructure/network/NetworkService"; import VCLLog from "../../../utils/VCLLog"; import Request, { HttpMethod } from "./Request"; @@ -10,7 +9,7 @@ import axios, { AxiosResponse } from "axios"; export default class NetworkServiceImpl implements NetworkService { static TAG = NetworkServiceImpl.name; - async sendRequestRaw(params: Request): Promise> { + async sendRequestRaw(params: Request): Promise { let handler: () => Nullish>> = () => { return null; }; @@ -39,9 +38,9 @@ export default class NetworkServiceImpl implements NetworkService { } try { const r = await handler(); - return new VCLResult.Success(new Response(r!.data, r!.status)); + return new Response(r!.data, r!.status); } catch (error: any) { - return new VCLResult.Error(error.response?.data ?? error); + return error.response?.data ?? error; } } @@ -52,7 +51,7 @@ export default class NetworkServiceImpl implements NetworkService { method: HttpMethod; headers: any; useCaches: boolean; - }): Promise> { + }): Promise { return this.sendRequestRaw(params); } diff --git a/packages/sdk/src/impl/data/models/CountriesModelImpl.ts b/packages/sdk/src/impl/data/models/CountriesModelImpl.ts index 2534859..1065cc3 100644 --- a/packages/sdk/src/impl/data/models/CountriesModelImpl.ts +++ b/packages/sdk/src/impl/data/models/CountriesModelImpl.ts @@ -1,6 +1,5 @@ import VCLCountries from "../../../api/entities/VCLCountries"; 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"; import { Nullish } from "../../../api/VCLTypes"; @@ -8,16 +7,10 @@ import { Nullish } from "../../../api/VCLTypes"; export default class CountriesModelImpl implements CountriesModel { constructor(private readonly countriesUseCase: CountriesUseCase) {} - data: Nullish; - async initialize(): Promise { - const result = await this.countriesUseCase.getCountries(); - - const [err, d] = result.handleResult(); - if (err) { - return new VCLError(err.message); - } + public data: Nullish; - this.data = result.getData(); + async initialize(): Promise { + this.data = await this.countriesUseCase.getCountries(); return null; } } diff --git a/packages/sdk/src/impl/data/models/CredentialTypeSchemasModelImpl.ts b/packages/sdk/src/impl/data/models/CredentialTypeSchemasModelImpl.ts index a818cd0..4f99930 100644 --- a/packages/sdk/src/impl/data/models/CredentialTypeSchemasModelImpl.ts +++ b/packages/sdk/src/impl/data/models/CredentialTypeSchemasModelImpl.ts @@ -1,6 +1,5 @@ import VCLCredentialTypeSchemas from "../../../api/entities/VCLCredentialTypeSchemas"; 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"; import { Nullish } from "../../../api/VCLTypes"; @@ -14,15 +13,7 @@ export default class CredentialTypeSchemasModelImpl data: Nullish; async initialize(): Promise { - const result = - await this.credentialTypeSchemasUseCase.getCredentialTypeSchemas(); - const [err, d] = result.handleResult(); - - if (err) { - return new VCLError(err.message); - } - - this.data = result.getData(); + this.data = await this.credentialTypeSchemasUseCase.getCredentialTypeSchemas(); return null; } } diff --git a/packages/sdk/src/impl/data/models/CredentialTypesModelImpl.ts b/packages/sdk/src/impl/data/models/CredentialTypesModelImpl.ts index e3e2bb5..7d18987 100644 --- a/packages/sdk/src/impl/data/models/CredentialTypesModelImpl.ts +++ b/packages/sdk/src/impl/data/models/CredentialTypesModelImpl.ts @@ -1,6 +1,5 @@ import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; 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"; import { Nullish } from "../../../api/VCLTypes"; @@ -11,13 +10,7 @@ export default class CredentialTypesModelImpl implements CredentialTypesModel { ) {} data: Nullish; async initialize(): Promise { - const result = await this.credentialTypesUseCase.getCredentialTypes(); - - const [err, d] = result.handleResult(); - if (err) { - return err; - } - this.data = result.getData(); + this.data = await this.credentialTypesUseCase.getCredentialTypes(); return null; } } diff --git a/packages/sdk/src/impl/data/repositories/CountriesRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/CountriesRepositoryImpl.ts index 7faa50b..74c3f5c 100644 --- a/packages/sdk/src/impl/data/repositories/CountriesRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/CountriesRepositoryImpl.ts @@ -3,7 +3,6 @@ import VCLCountries from "../../../api/entities/VCLCountries"; import VCLCountry from "../../../api/entities/VCLCountry"; import VCLRegion from "../../../api/entities/VCLRegion"; import VCLRegions from "../../../api/entities/VCLRegions"; -import VCLResult from "../../../api/entities/VCLResult"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import CountriesRepository from "../../domain/repositories/CountriesRepository"; import Request, { HttpMethod } from "../infrastructure/network/Request"; @@ -12,37 +11,30 @@ import Urls, { HeaderKeys, HeaderValues } from "./Urls"; export default class CountriesRepositoryImpl implements CountriesRepository { constructor(private readonly networkService: NetworkService) {} - getCountries(): Promise> { + getCountries(): Promise { return this.fetchCountries(Urls.Countries); } private async fetchCountries( endpoint: string - ): Promise> { - const result = await this.networkService.sendRequest({ + ): Promise { + const countriesResponse = await this.networkService.sendRequest({ endpoint, contentType: Request.ContentTypeApplicationJson, method: HttpMethod.GET, headers: { [HeaderKeys.XVnfProtocolVersion]: - HeaderValues.XVnfProtocolVersion, + HeaderValues.XVnfProtocolVersion, }, useCaches: true, body: null, }); - const [error, countriesResponse] = result.handleResult(); - if (error) { - return new VCLResult.Error(error); - } - - return new VCLResult.Success( - new VCLCountries( - (countriesResponse!.payload as Dictionary[]).map((i) => - this.parseCountry(i) - ) + return new VCLCountries( + (countriesResponse.payload as Dictionary[]).map((i) => + this.parseCountry(i) ) - ); + ) } private parseCountry(countryJsonObj: Dictionary): VCLCountry { diff --git a/packages/sdk/src/impl/data/repositories/CredentialManifestRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/CredentialManifestRepositoryImpl.ts index 367ea07..716a05e 100644 --- a/packages/sdk/src/impl/data/repositories/CredentialManifestRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/CredentialManifestRepositoryImpl.ts @@ -1,11 +1,9 @@ import VCLCredentialManifest from "../../../api/entities/VCLCredentialManifest"; import VCLCredentialManifestDescriptor from "../../../api/entities/VCLCredentialManifestDescriptor"; 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"; import { HttpMethod } from "../infrastructure/network/Request"; -import Response from "../infrastructure/network/Response"; import { HeaderKeys, HeaderValues } from "./Urls"; export default class CredentialManifestRepositoryImpl @@ -15,15 +13,13 @@ export default class CredentialManifestRepositoryImpl async getCredentialManifest( credentialManifestDescriptor: VCLCredentialManifestDescriptor - ): Promise> { + ): Promise { const endpoint = credentialManifestDescriptor.endpoint; if (!endpoint) { - return new VCLResult.Error( - new VCLError("credentialManifestDescriptor.endpoint = null") - ); + throw new VCLError("credentialManifestDescriptor.endpoint = null"); } - const result = await this.networkService.sendRequest({ + const credentialManifestResponse = await this.networkService.sendRequest({ endpoint, method: HttpMethod.GET, body: null, @@ -35,15 +31,6 @@ export default class CredentialManifestRepositoryImpl contentType: null, useCaches: false, }); - const [err, credentialManifestResponse] = result.handleResult(); - if (err) { - return new VCLResult.Error(err); - } - try { - const jwtStr = credentialManifestResponse!.payload[VCLCredentialManifest.KeyIssuingRequest]; - return new VCLResult.Success(jwtStr); - } catch (error: any) { - return new VCLResult.Error(new VCLError(error)); - } + return credentialManifestResponse.payload[VCLCredentialManifest.KeyIssuingRequest]; } } diff --git a/packages/sdk/src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl.ts index a4fea28..ce4def1 100644 --- a/packages/sdk/src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl.ts @@ -1,9 +1,9 @@ import VCLCredentialTypeSchema from "../../../api/entities/VCLCredentialTypeSchema"; -import VCLResult from "../../../api/entities/VCLResult"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import CredentialTypeSchemaRepository from "../../domain/repositories/CredentialTypeSchemaRepository"; import { HttpMethod } from "../infrastructure/network/Request"; import Urls, { HeaderKeys, HeaderValues } from "./Urls"; +import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; export default class CredentialTypeSchemaRepositoryImpl implements CredentialTypeSchemaRepository @@ -12,7 +12,7 @@ export default class CredentialTypeSchemaRepositoryImpl getCredentialTypeSchema( schemaName: string - ): Promise> { + ): Promise { return this.fetchCredentialTypeSchema( Urls.CredentialTypeSchemas + schemaName ); @@ -20,26 +20,18 @@ export default class CredentialTypeSchemaRepositoryImpl private async fetchCredentialTypeSchema( endpoint: string - ): Promise> { - const result = await this.networkService.sendRequest({ + ): Promise { + const credentialTypeSchemaResponse = await this.networkService.sendRequest({ endpoint, method: HttpMethod.GET, body: null, useCaches: true, headers: { [HeaderKeys.XVnfProtocolVersion]: - HeaderValues.XVnfProtocolVersion, + HeaderValues.XVnfProtocolVersion, }, contentType: null, }); - - const [error, credentialTypeSchemaResponse] = result.handleResult(); - if (error) { - return new VCLResult.Error(error); - } - - return new VCLResult.Success( - new VCLCredentialTypeSchema(credentialTypeSchemaResponse!.payload) - ); + return new VCLCredentialTypeSchema(credentialTypeSchemaResponse.payload) } } diff --git a/packages/sdk/src/impl/data/repositories/CredentialTypesRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/CredentialTypesRepositoryImpl.ts index b438fd1..8a1eabd 100644 --- a/packages/sdk/src/impl/data/repositories/CredentialTypesRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/CredentialTypesRepositoryImpl.ts @@ -1,6 +1,5 @@ import VCLCredentialType from "../../../api/entities/VCLCredentialType"; import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; -import VCLResult from "../../../api/entities/VCLResult"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import CredentialTypesRepository from "../../domain/repositories/CredentialTypesRepository"; import Request, { HttpMethod } from "../infrastructure/network/Request"; @@ -8,50 +7,43 @@ import Urls, { HeaderKeys, HeaderValues } from "./Urls"; import { Dictionary } from "../../../api/VCLTypes"; export default class CredentialTypesRepositoryImpl - implements CredentialTypesRepository -{ - constructor(private readonly networkService: NetworkService) {} + implements CredentialTypesRepository { + constructor(private readonly networkService: NetworkService) { + } - async getCredentialTypes(): Promise> { + async getCredentialTypes(): Promise { const endpoint = Urls.CredentialTypes; return await this.fetchCredentialTypes(endpoint); } async fetchCredentialTypes( endpoint: string - ): Promise> { - const result = await this.networkService.sendRequest({ + ): Promise { + const credentialTypesResponse = await this.networkService.sendRequest({ endpoint, contentType: Request.ContentTypeApplicationJson, method: HttpMethod.GET, headers: { [HeaderKeys.XVnfProtocolVersion]: - HeaderValues.XVnfProtocolVersion, + HeaderValues.XVnfProtocolVersion, }, useCaches: true, body: null, }); - - const [err, credentialTypesResponse] = result.handleResult(); - if (err) { - return new VCLResult.Error(err); - } - return new VCLResult.Success( - new VCLCredentialTypes( - (credentialTypesResponse!.payload as Dictionary[]).map( - (item: Dictionary) => { - return new VCLCredentialType( - item, - item[VCLCredentialType.KeyId], - item[VCLCredentialType.KeySchema], - item[VCLCredentialType.KeyCreatedAt], - item[VCLCredentialType.KeySchemaName], - item[VCLCredentialType.KeyCredentialType], - item[VCLCredentialType.KeyRecommended] - ); - } - ) + return new VCLCredentialTypes( + (credentialTypesResponse.payload as Dictionary[]).map( + (item: Dictionary) => { + return new VCLCredentialType( + item, + item[VCLCredentialType.KeyId], + item[VCLCredentialType.KeySchema], + item[VCLCredentialType.KeyCreatedAt], + item[VCLCredentialType.KeySchemaName], + item[VCLCredentialType.KeyCredentialType], + item[VCLCredentialType.KeyRecommended] + ); + } ) - ); + ) } } diff --git a/packages/sdk/src/impl/data/repositories/CredentialTypesUIFormSchemaRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/CredentialTypesUIFormSchemaRepositoryImpl.ts index 2bc3822..63f57bd 100644 --- a/packages/sdk/src/impl/data/repositories/CredentialTypesUIFormSchemaRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/CredentialTypesUIFormSchemaRepositoryImpl.ts @@ -4,7 +4,6 @@ import VCLCredentialTypesUIFormSchema from "../../../api/entities/VCLCredentialT import VCLCredentialTypesUIFormSchemaDescriptor from "../../../api/entities/VCLCredentialTypesUIFormSchemaDescriptor"; import VCLPlace from "../../../api/entities/VCLPlace"; import VCLRegions from "../../../api/entities/VCLRegions"; -import VCLResult from "../../../api/entities/VCLResult"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import CredentialTypesUIFormSchemaRepository from "../../domain/repositories/CredentialTypesUIFormSchemaRepository"; import Request, { HttpMethod } from "../infrastructure/network/Request"; @@ -18,8 +17,8 @@ export default class CredentialTypesUIFormSchemaRepositoryImpl async getCredentialTypesUIFormSchema( credentialTypesUIFormSchemaDescriptor: VCLCredentialTypesUIFormSchemaDescriptor, countries: VCLCountries - ): Promise> { - const result = await this.networkService.sendRequest({ + ): Promise { + const credentialTypesFormSchemaResponse = await this.networkService.sendRequest({ endpoint: Urls.CredentialTypesFormSchema.replace( Params.CredentialType, credentialTypesUIFormSchemaDescriptor.credentialType @@ -28,30 +27,23 @@ export default class CredentialTypesUIFormSchemaRepositoryImpl contentType: Request.ContentTypeApplicationJson, headers: { [HeaderKeys.XVnfProtocolVersion]: - HeaderValues.XVnfProtocolVersion, + HeaderValues.XVnfProtocolVersion, }, useCaches: true, body: null, }); - const [err, credentialTypesFormSchemaResponse] = result.handleResult(); - - if (err) { - return new VCLResult.Error(err); - } const country = countries.countryByCode( credentialTypesUIFormSchemaDescriptor.countryCode ); - return new VCLResult.Success( - new VCLCredentialTypesUIFormSchema( - this.parseCredentialTypesUIFormSchema( - countries, - credentialTypesFormSchemaResponse?.payload, - country?.regions - ) + return new VCLCredentialTypesUIFormSchema( + this.parseCredentialTypesUIFormSchema( + countries, + credentialTypesFormSchemaResponse?.payload, + country?.regions ) - ); + ) } private parseCredentialTypesUIFormSchema( diff --git a/packages/sdk/src/impl/data/repositories/ExchangeProgressRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/ExchangeProgressRepositoryImpl.ts index c61d535..f87ff6e 100644 --- a/packages/sdk/src/impl/data/repositories/ExchangeProgressRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/ExchangeProgressRepositoryImpl.ts @@ -1,8 +1,6 @@ import { Dictionary } from "../../../api/VCLTypes"; -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"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import ExchangeProgressRepository from "../../domain/repositories/ExchangeProgressRepository"; import { HttpMethod } from "../infrastructure/network/Request"; @@ -15,8 +13,8 @@ export default class ExchangeProgressRepositoryImpl async getExchangeProgress( exchangeDescriptor: VCLExchangeDescriptor - ): Promise> { - const submissionResult = await this.networkService.sendRequest({ + ): Promise { + const exchangeProgressResponse = await this.networkService.sendRequest({ useCaches: false, method: HttpMethod.GET, endpoint: @@ -33,20 +31,7 @@ export default class ExchangeProgressRepositoryImpl contentType: null, }); - const [error, exchangeProgressResponse] = - submissionResult.handleResult(); - - if (error) { - return new VCLResult.Error(error); - } - - try { - return new VCLResult.Success( - this.parseExchange(exchangeProgressResponse?.payload) - ); - } catch (error: any) { - return new VCLResult.Error(new VCLError(error)); - } + return this.parseExchange(exchangeProgressResponse.payload) } private parseExchange(exchangeJsonObj: Dictionary) { diff --git a/packages/sdk/src/impl/data/repositories/FinalizeOffersRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/FinalizeOffersRepositoryImpl.ts index 50cf2df..5efd2cd 100644 --- a/packages/sdk/src/impl/data/repositories/FinalizeOffersRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/FinalizeOffersRepositoryImpl.ts @@ -1,51 +1,38 @@ import { Nullish } from "../../../api/VCLTypes"; import VCLError from "../../../api/entities/error/VCLError"; import VCLFinalizeOffersDescriptor from "../../../api/entities/VCLFinalizeOffersDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLToken from "../../../api/entities/VCLToken"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import FinalizeOffersRepository from "../../domain/repositories/FinalizeOffersRepository"; import { HttpMethod } from "../infrastructure/network/Request"; import { HeaderKeys, HeaderValues } from "./Urls"; +import VCLJwt from "../../../api/entities/VCLJwt"; export class FinalizeOffersRepositoryImpl implements FinalizeOffersRepository { - constructor(private networkService: NetworkService) {} + constructor(private networkService: NetworkService) { + } async finalizeOffers( - token: VCLToken, - finalizeOffersDescriptor: VCLFinalizeOffersDescriptor - ): Promise> { - const result = await this.networkService.sendRequest({ + finalizeOffersDescriptor: VCLFinalizeOffersDescriptor, + sessionToken: VCLToken + ): Promise { + const finalizedOffersResponse = await this.networkService.sendRequest({ useCaches: false, endpoint: finalizeOffersDescriptor.finalizeOffersUri, body: finalizeOffersDescriptor.payload, headers: { - [HeaderKeys.HeaderKeyAuthorization]: `${HeaderKeys.HeaderValuePrefixBearer} ${token.value}`, + [HeaderKeys.HeaderKeyAuthorization]: `${HeaderKeys.HeaderValuePrefixBearer} ${sessionToken.value}`, [HeaderKeys.XVnfProtocolVersion]: - HeaderValues.XVnfProtocolVersion, + HeaderValues.XVnfProtocolVersion, }, contentType: "application/json", method: HttpMethod.POST, }); - const [error, finalizedOffersResponse] = result.handleResult(); - if (error) { - return new VCLResult.Error(error); - } - - try { - const encodedJwts: Nullish = finalizedOffersResponse! - .payload as Nullish; + const encodedJwts: Nullish = finalizedOffersResponse.payload as Nullish; - if (encodedJwts) { - return new VCLResult.Success(encodedJwts); - } - return new VCLResult.Error( - new VCLError( - `Failed to parse: ${finalizedOffersResponse!.payload}` - ) - ); - } catch (error: any) { - return new VCLResult.Error(new VCLError(error)); + if (encodedJwts) { + return encodedJwts.map((encodedJwt) => VCLJwt.fromEncodedJwt(encodedJwt)); } + throw new VCLError(`Failed to parse: ${finalizedOffersResponse!.payload}`); } } diff --git a/packages/sdk/src/impl/data/repositories/GenerateOffersRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/GenerateOffersRepositoryImpl.ts index 805107c..1b80164 100644 --- a/packages/sdk/src/impl/data/repositories/GenerateOffersRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/GenerateOffersRepositoryImpl.ts @@ -1,7 +1,6 @@ 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"; import VCLToken from "../../../api/entities/VCLToken"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import GenerateOffersRepository from "../../domain/repositories/GenerateOffersRepository"; @@ -16,14 +15,14 @@ export default class GenerateOffersRepositoryImpl } async generateOffers( - token: VCLToken, - generateOffersDescriptor: VCLGenerateOffersDescriptor - ): Promise> { - const result = await this.networkService.sendRequest({ + generateOffersDescriptor: VCLGenerateOffersDescriptor, + sessionToken: VCLToken + ): Promise { + const offersResponse = await this.networkService.sendRequest({ useCaches: false, endpoint: generateOffersDescriptor.checkOffersUri, headers: { - [HeaderKeys.HeaderKeyAuthorization]: `${HeaderKeys.HeaderValuePrefixBearer} ${token.value}`, + [HeaderKeys.HeaderKeyAuthorization]: `${HeaderKeys.HeaderValuePrefixBearer} ${sessionToken.value}`, [HeaderKeys.XVnfProtocolVersion]: HeaderValues.XVnfProtocolVersion, }, @@ -31,19 +30,10 @@ export default class GenerateOffersRepositoryImpl method: HttpMethod.POST, contentType: "application/json", }); - const [error, offersResponse] = result.handleResult(); - if (error) { - return new VCLResult.Error(error); - } if (offersResponse) { - try { - return new VCLResult.Success(this.parse(offersResponse, token)); - } catch (error: any) { - return new VCLResult.Error(new VCLError(error)); - } + return this.parse(offersResponse, sessionToken); } - - return new VCLResult.Error(new VCLError("Offers did not returned.")); + throw new VCLError("Offers did not returned."); } parse(offersResponse: Response, sessionToken: VCLToken): VCLOffers { diff --git a/packages/sdk/src/impl/data/repositories/JwtServiceRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/JwtServiceRepositoryImpl.ts index f1a5ac8..b9fea01 100644 --- a/packages/sdk/src/impl/data/repositories/JwtServiceRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/JwtServiceRepositoryImpl.ts @@ -1,9 +1,7 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; -import VCLError from "../../../api/entities/error/VCLError"; import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; -import VCLJwt, { SignedJWT } from "../../../api/entities/VCLJwt"; +import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository"; import VCLJwtSignService from "../../../api/jwt/VCLJwtSignService"; import VCLJwtVerifyService from "../../../api/jwt/VCLJwtVerifyService"; @@ -15,51 +13,32 @@ export default class JwtServiceRepositoryImpl implements JwtServiceRepository { private readonly jwtSignService: VCLJwtSignService, private readonly jwtVerifyService: VCLJwtVerifyService ) {} - - async decode(encodedJwt: string): Promise> { - try { - const parsed = SignedJWT.parse(encodedJwt); - if (parsed) { - return new VCLResult.Success(new VCLJwt(parsed)); - } - - throw new Error(`Failed to parse ${encodedJwt}`); - } catch (ex: any) { - return new VCLResult.Error(new VCLError(ex)); - } + async decode(encodedJwt: string): Promise { + return VCLJwt.fromEncodedJwt(encodedJwt); } + async verifyJwt( jwt: VCLJwt, publicJwk: Nullish, remoteCryptoServicesToken: Nullish - ): Promise> { - try { - return await this.jwtVerifyService.verify( - jwt, - publicJwk, - remoteCryptoServicesToken - ); - } catch (error: any) { - return new VCLResult.Error(new VCLError(error!)); - } + ): Promise { + return await this.jwtVerifyService.verify( + jwt, + publicJwk, + remoteCryptoServicesToken + ); } async generateSignedJwt( jwtDescriptor: VCLJwtDescriptor, didJwk: VCLDidJwk, nonce: Nullish, remoteCryptoServicesToken: Nullish - ): Promise> { - try { - return await this.jwtSignService.sign( - jwtDescriptor, - didJwk, - nonce, - remoteCryptoServicesToken - ); - } catch (error) { - return new VCLResult.Error( - new VCLError(`Failed to sign ${jwtDescriptor.payload}`) - ); - } + ): Promise { + return await this.jwtSignService.sign( + jwtDescriptor, + didJwk, + nonce, + remoteCryptoServicesToken + ); } } diff --git a/packages/sdk/src/impl/data/repositories/KeyServiceRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/KeyServiceRepositoryImpl.ts index 10a7880..ad587e5 100644 --- a/packages/sdk/src/impl/data/repositories/KeyServiceRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/KeyServiceRepositoryImpl.ts @@ -1,6 +1,5 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLKeyService from "../../../api/keys/VCLKeyService"; import KeyServiceRepository from "../../domain/repositories/KeyServiceRepository"; @@ -13,7 +12,7 @@ export default class KeyServiceRepositoryImpl implements KeyServiceRepository { async generateDidJwk( didJwkDescriptor: VCLDidJwkDescriptor, - ): Promise> { + ): Promise { return this.keyService.generateDidJwk(didJwkDescriptor); } } diff --git a/packages/sdk/src/impl/data/repositories/OrganizationsRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/OrganizationsRepositoryImpl.ts index d07d28f..eae5b8b 100644 --- a/packages/sdk/src/impl/data/repositories/OrganizationsRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/OrganizationsRepositoryImpl.ts @@ -1,9 +1,7 @@ import { Dictionary, Nullish } from "../../../api/VCLTypes"; -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"; -import VCLResult from "../../../api/entities/VCLResult"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import OrganizationsRepository from "../../domain/repositories/OrganizationsRepository"; import { HttpMethod } from "../infrastructure/network/Request"; @@ -15,14 +13,14 @@ export default class OrganizationsRepositoryImpl constructor(private networkService: NetworkService) {} async searchForOrganizations( organizationsSearchDescriptor: VCLOrganizationsSearchDescriptor - ): Promise> { + ): Promise { const endpoint = organizationsSearchDescriptor.queryParams ? Urls.Organizations + "?" + organizationsSearchDescriptor.queryParams : Urls.Organizations; - const result = await this.networkService.sendRequest({ + const organizationsResponse = await this.networkService.sendRequest({ useCaches: false, endpoint, headers: { @@ -33,18 +31,7 @@ export default class OrganizationsRepositoryImpl method: HttpMethod.GET, contentType: null, }); - - const [error, organizationsResponse] = result.handleResult(); - if (error) { - return new VCLResult.Error(error); - } - try { - return new VCLResult.Success( - this.parse(organizationsResponse!.payload) - ); - } catch (error: any) { - return new VCLResult.Error(new VCLError(error)); - } + return this.parse(organizationsResponse.payload) } private parse(organizationsRaw: Dictionary): VCLOrganizations { diff --git a/packages/sdk/src/impl/data/repositories/PresentationRequestRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/PresentationRequestRepositoryImpl.ts index 7db88fd..6496c66 100644 --- a/packages/sdk/src/impl/data/repositories/PresentationRequestRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/PresentationRequestRepositoryImpl.ts @@ -1,7 +1,6 @@ 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"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; import PresentationRequestRepository from "../../domain/repositories/PresentationRequestRepository"; import { HttpMethod } from "../infrastructure/network/Request"; @@ -14,15 +13,13 @@ export default class PresentationRequestRepositoryImpl async getPresentationRequest( presentationRequestDescriptor: VCLPresentationRequestDescriptor - ): Promise> { + ): Promise { const endpoint = presentationRequestDescriptor.endpoint; if (!endpoint) { - return new VCLResult.Error( - new VCLError("presentationRequestDescriptor.endpoint = null") - ); + throw new VCLError("presentationRequestDescriptor.endpoint = null"); } - const encodedJwtResult = await this.networkService.sendRequest({ + const presentationRequestResponse = await this.networkService.sendRequest({ endpoint, contentType: null, method: HttpMethod.GET, @@ -33,19 +30,8 @@ export default class PresentationRequestRepositoryImpl body: null, useCaches: false, }); - - const [error, presentationRequestResponse] = encodedJwtResult.handleResult(); - if (error) { - return new VCLResult.Error(error); - } - try { - const encodedJwtStr = - presentationRequestResponse!.payload[ - VCLPresentationRequest.KeyPresentationRequest - ]; - return new VCLResult.Success(encodedJwtStr); - } catch (error: any) { - return new VCLResult.Error(new VCLError(error)); - } + return presentationRequestResponse.payload[ + VCLPresentationRequest.KeyPresentationRequest + ]; } } diff --git a/packages/sdk/src/impl/data/repositories/ResolveKidRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/ResolveKidRepositoryImpl.ts index f8db717..8849b4f 100644 --- a/packages/sdk/src/impl/data/repositories/ResolveKidRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/ResolveKidRepositoryImpl.ts @@ -1,5 +1,4 @@ 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"; import { HttpMethod } from "../infrastructure/network/Request"; @@ -8,8 +7,8 @@ import Urls, { HeaderKeys, HeaderValues } from "./Urls"; export default class ResolveKidRepositoryImpl implements ResolveKidRepository { constructor(private readonly networkService: NetworkService) {} - async getPublicKey(kid: string): Promise> { - const result = await this.networkService.sendRequest({ + async getPublicKey(kid: string): Promise { + const publicKeyResponse = await this.networkService.sendRequest({ endpoint: Urls.ResolveKid + kid + `?format=${VCLPublicJwk.Format.jwk}`, method: HttpMethod.GET, @@ -21,14 +20,6 @@ export default class ResolveKidRepositoryImpl implements ResolveKidRepository { contentType: null, useCaches: false, }); - - const [error, publicKeyResponse] = result.handleResult(); - if (error) { - return new VCLResult.Error(error); - } - - return new VCLResult.Success( - VCLPublicJwk.fromJSON(publicKeyResponse!.payload) - ); + return 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 85e333d..ed8052a 100644 --- a/packages/sdk/src/impl/data/repositories/SubmissionRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/SubmissionRepositoryImpl.ts @@ -1,8 +1,6 @@ import { Dictionary } from "../../../api/VCLTypes"; -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"; import VCLSubmission from "../../../api/entities/VCLSubmission"; import VCLSubmissionResult from "../../../api/entities/VCLSubmissionResult"; import VCLToken from "../../../api/entities/VCLToken"; @@ -16,12 +14,10 @@ export default class SubmissionRepositoryImpl implements SubmissionRepository { async submit( submission: VCLSubmission, jwt: VCLJwt - ): Promise> { - const body = submission.generateRequestBody(jwt); - - const result = await this.networkService.sendRequest({ + ): Promise { + const submissionResponse = await this.networkService.sendRequest({ endpoint: submission.submitUri, - body, + body: submission.generateRequestBody(jwt), method: HttpMethod.POST, headers: { [HeaderKeys.XVnfProtocolVersion]: @@ -30,24 +26,11 @@ export default class SubmissionRepositoryImpl implements SubmissionRepository { contentType: "application/json", useCaches: false, }); - - const [error, submissionResponse] = result.handleResult(); - - if (submissionResponse) { - try { - const jsonObj = submissionResponse.payload; - const submissionResult = this.parse( - jsonObj, - submission.jti, - submission.submissionId - ); - return new VCLResult.Success(submissionResult); - } catch (error: any) { - return new VCLResult.Error(new VCLError(error)); - } - } - - return new VCLResult.Error(error!); + return this.parse( + submissionResponse.payload, + submission.jti, + submission.submissionId + ); } private parseExchange(exchangeJsonObj: Dictionary) { diff --git a/packages/sdk/src/impl/data/repositories/VerifiedProfileRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/VerifiedProfileRepositoryImpl.ts index 7c8223c..f77bbb3 100644 --- a/packages/sdk/src/impl/data/repositories/VerifiedProfileRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/VerifiedProfileRepositoryImpl.ts @@ -1,4 +1,3 @@ -import VCLResult from "../../../api/entities/VCLResult"; import VCLVerifiedProfile from "../../../api/entities/VCLVerifiedProfile"; import VCLVerifiedProfileDescriptor from "../../../api/entities/VCLVerifiedProfileDescriptor"; import NetworkService from "../../domain/infrastructure/network/NetworkService"; @@ -11,10 +10,8 @@ export default class VerifiedProfileRepositoryImpl { constructor(private readonly networkService: NetworkService) {} - async getVerifiedProfile( - verifiedProfileDescriptor: VCLVerifiedProfileDescriptor - ): Promise> { - const result = await this.networkService.sendRequest({ + async getVerifiedProfile(verifiedProfileDescriptor: VCLVerifiedProfileDescriptor): Promise { + const verifiedProfileResponse = await this.networkService.sendRequest({ method: HttpMethod.GET, endpoint: Urls.VerifiedProfile.replace( Params.Did, @@ -28,14 +25,6 @@ export default class VerifiedProfileRepositoryImpl contentType: null, useCaches: false, }); - - const [err, verifiedProfileResponse] = result.handleResult(); - if (err) { - return new VCLResult.Error(err); - } - - return new VCLResult.Success( - new VCLVerifiedProfile(verifiedProfileResponse!.payload) - ); + return new VCLVerifiedProfile(verifiedProfileResponse.payload) } } diff --git a/packages/sdk/src/impl/data/usecases/CountriesModelUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/CountriesModelUseCaseImpl.ts index 3133f48..1c971e1 100644 --- a/packages/sdk/src/impl/data/usecases/CountriesModelUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/CountriesModelUseCaseImpl.ts @@ -1,12 +1,15 @@ import VCLCountries from "../../../api/entities/VCLCountries"; -import VCLResult from "../../../api/entities/VCLResult"; import CountriesRepository from "../../domain/repositories/CountriesRepository"; import CountriesUseCase from "../../domain/usecases/CountriesModelUseCase"; export default class CountriesUseCaseImpl implements CountriesUseCase { constructor(private readonly countriesRepository: CountriesRepository) {} - getCountries(): Promise> { - return this.countriesRepository.getCountries(); + async getCountries(): Promise { + try { + return await this.countriesRepository.getCountries(); + } catch (error: any) { + throw new Error(error); + } } } diff --git a/packages/sdk/src/impl/data/usecases/CredentialManifestUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/CredentialManifestUseCaseImpl.ts index 1fe46a2..17d5427 100644 --- a/packages/sdk/src/impl/data/usecases/CredentialManifestUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/CredentialManifestUseCaseImpl.ts @@ -3,7 +3,6 @@ import VCLCredentialManifestDescriptor from "../../../api/entities/VCLCredential 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"; import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository"; import ResolveKidRepository from "../../domain/repositories/ResolveKidRepository"; @@ -11,27 +10,21 @@ import CredentialManifestUseCase from "../../domain/usecases/CredentialManifestU import VCLVerifiedProfile from "../../../api/entities/VCLVerifiedProfile"; export default class CredentialManifestUseCaseImpl - implements CredentialManifestUseCase -{ + implements CredentialManifestUseCase { constructor( private readonly credentialManifestRepository: CredentialManifestRepository, private readonly resolveKidRepository: ResolveKidRepository, private readonly jwtServiceRepository: JwtServiceRepository - ) {} + ) { + } async getCredentialManifest( credentialManifestDescriptor: VCLCredentialManifestDescriptor, verifiedProfile: VCLVerifiedProfile - ): Promise> { - const jwtStrResult = - await this.credentialManifestRepository.getCredentialManifest( - credentialManifestDescriptor - ); - const [error, jwtStr] = jwtStrResult.handleResult(); - if (error) { - return this.onError(error); - } - + ): Promise { + const jwtStr = await this.credentialManifestRepository.getCredentialManifest( + credentialManifestDescriptor + ); return this.onGetCredentialManifestSuccess( new VCLCredentialManifest( VCLJwt.fromEncodedJwt(jwtStr!), @@ -46,7 +39,7 @@ export default class CredentialManifestUseCaseImpl async onGetCredentialManifestSuccess( credentialManifest: VCLCredentialManifest - ): Promise> { + ): Promise { // TODO: Here we should verify the credential manifest in future // credentialManifestByDeepLinkVerifier.verifyCredentialManifest(credentialManifest, deepLink) { return this.onCredentialManifestDidVerificationSuccess(credentialManifest); @@ -54,57 +47,36 @@ export default class CredentialManifestUseCaseImpl async onCredentialManifestDidVerificationSuccess( credentialManifest: VCLCredentialManifest - ): Promise> { + ): Promise { const kid = credentialManifest.jwt.kid?.replace("#", encodeURIComponent("#")); if (!kid) { - return this.onError(new VCLError("Empty kid")); + throw new VCLError("Empty kid"); } - const publicKeyResult = await this.resolveKidRepository.getPublicKey(kid); + const publicKey = await this.resolveKidRepository.getPublicKey(kid); - const [err, publicKey] = publicKeyResult.handleResult(); - if (err) { - this.onError(err); - } - return this.onResolvePublicKeySuccess( - publicKey!, - credentialManifest, - ); + return this.onResolvePublicKeySuccess(publicKey, credentialManifest,); } async onResolvePublicKeySuccess( publicJwk: VCLPublicJwk, credentialManifest: VCLCredentialManifest, - ): Promise> { - const verificationResult = await this.jwtServiceRepository.verifyJwt( + ): Promise { + const isVerified = await this.jwtServiceRepository.verifyJwt( credentialManifest.jwt, publicJwk, credentialManifest.remoteCryptoServicesToken ); - - const [err, isVerified] = verificationResult.handleResult(); - if (err) { - return this.onError(err); - } - return this.onVerificationSuccess( - isVerified!, - credentialManifest - ); + return this.onVerificationSuccess(isVerified, credentialManifest); } async onVerificationSuccess( isVerified: boolean, credentialManifest: VCLCredentialManifest, - ): Promise> { + ): Promise { if (isVerified) { - return new VCLResult.Success(credentialManifest); + return credentialManifest; } else { - return this.onError( - new VCLError(`Failed to verify credentialManifest jwt:\n${credentialManifest.jwt}`), - ) + throw new VCLError(`Failed to verify credentialManifest jwt:\n${credentialManifest.jwt}`); } } - - onError(error: VCLError): VCLResult { - return new VCLResult.Error(error); - } } diff --git a/packages/sdk/src/impl/data/usecases/CredentialTypeSchemasUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/CredentialTypeSchemasUseCaseImpl.ts index aec0a2e..676708a 100644 --- a/packages/sdk/src/impl/data/usecases/CredentialTypeSchemasUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/CredentialTypeSchemasUseCaseImpl.ts @@ -2,10 +2,8 @@ import VCLCredentialType from "../../../api/entities/VCLCredentialType"; import VCLCredentialTypeSchema from "../../../api/entities/VCLCredentialTypeSchema"; import VCLCredentialTypeSchemas from "../../../api/entities/VCLCredentialTypeSchemas"; import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; -import VCLResult from "../../../api/entities/VCLResult"; import CredentialTypeSchemaRepository from "../../domain/repositories/CredentialTypeSchemaRepository"; import CredentialTypeSchemasUseCase from "../../domain/usecases/CredentialTypeSchemasUseCase"; -import VCLLog from "../../utils/VCLLog"; export default class CredentialTypeSchemasUseCaseImpl implements CredentialTypeSchemasUseCase @@ -17,13 +15,10 @@ export default class CredentialTypeSchemasUseCaseImpl private readonly credentialTypes: VCLCredentialTypes ) {} - async getCredentialTypeSchemas(): Promise< - VCLResult - > { + async getCredentialTypeSchemas(): Promise { const credentialTypeSchemasMap: { [key: string]: VCLCredentialTypeSchema; } = {}; - let credentialTypeSchemasMapIsEmpty = true; const schemaNamesArr: string[] = this.credentialTypes.all @@ -35,18 +30,9 @@ export default class CredentialTypeSchemasUseCaseImpl }) ?? []; for (const schemaName of schemaNamesArr) { - const result = - await this.credentialTypeSchemaRepository.getCredentialTypeSchema( - schemaName - ); - if (result && result.getData()) { - credentialTypeSchemasMap[schemaName] = result.getData()!; - credentialTypeSchemasMapIsEmpty = false; - } + credentialTypeSchemasMap[schemaName] = + await this.credentialTypeSchemaRepository.getCredentialTypeSchema(schemaName); } - - return new VCLResult.Success( - new VCLCredentialTypeSchemas(credentialTypeSchemasMap) - ); + return new VCLCredentialTypeSchemas(credentialTypeSchemasMap); } } diff --git a/packages/sdk/src/impl/data/usecases/CredentialTypesUIFormSchemaUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/CredentialTypesUIFormSchemaUseCaseImpl.ts index 8c11bdd..6a524a9 100644 --- a/packages/sdk/src/impl/data/usecases/CredentialTypesUIFormSchemaUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/CredentialTypesUIFormSchemaUseCaseImpl.ts @@ -1,7 +1,6 @@ import VCLCountries from "../../../api/entities/VCLCountries"; import VCLCredentialTypesUIFormSchema from "../../../api/entities/VCLCredentialTypesUIFormSchema"; import VCLCredentialTypesUIFormSchemaDescriptor from "../../../api/entities/VCLCredentialTypesUIFormSchemaDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import CredentialTypesUIFormSchemaRepository from "../../domain/repositories/CredentialTypesUIFormSchemaRepository"; import CredentialTypesUIFormSchemaUseCase from "../../domain/usecases/CredentialTypesUIFormSchemaUseCase"; @@ -12,13 +11,17 @@ export default class CredentialTypesUIFormSchemaUseCaseImpl private readonly credentialTypesUIFormSchemaRepository: CredentialTypesUIFormSchemaRepository ) {} - getCredentialTypesUIFormSchema( + async getCredentialTypesUIFormSchema( credentialTypesUIFormSchemaDescriptor: VCLCredentialTypesUIFormSchemaDescriptor, countries: VCLCountries - ): Promise> { - return this.credentialTypesUIFormSchemaRepository.getCredentialTypesUIFormSchema( - credentialTypesUIFormSchemaDescriptor, - countries - ); + ): Promise { + try { + return await this.credentialTypesUIFormSchemaRepository.getCredentialTypesUIFormSchema( + credentialTypesUIFormSchemaDescriptor, + countries + ); + } catch (error: any) { + throw new Error(error); + } } } diff --git a/packages/sdk/src/impl/data/usecases/CredentialTypesUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/CredentialTypesUseCaseImpl.ts index 096efbe..b3537a1 100644 --- a/packages/sdk/src/impl/data/usecases/CredentialTypesUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/CredentialTypesUseCaseImpl.ts @@ -1,14 +1,17 @@ import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; -import VCLResult from "../../../api/entities/VCLResult"; import CredentialTypesRepository from "../../domain/repositories/CredentialTypesRepository"; import { CredentialTypesUseCase } from "../../domain/usecases/CredentialTypesUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class CredentialTypesUseCaseImpl implements CredentialTypesUseCase { constructor(private readonly credentialTypes: CredentialTypesRepository) {} - async getCredentialTypes(): Promise> { - const it = await this.credentialTypes.getCredentialTypes(); - return it; + async getCredentialTypes(): Promise { + try { + return await this.credentialTypes.getCredentialTypes(); + } catch (error: any) { + throw new VCLError(error); + } } } diff --git a/packages/sdk/src/impl/data/usecases/ExchangeProgressUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/ExchangeProgressUseCaseImpl.ts index e6e2952..9141191 100644 --- a/packages/sdk/src/impl/data/usecases/ExchangeProgressUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/ExchangeProgressUseCaseImpl.ts @@ -1,20 +1,19 @@ import VCLExchange from "../../../api/entities/VCLExchange"; import VCLExchangeDescriptor from "../../../api/entities/VCLExchangeDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import ExchangeProgressRepository from "../../domain/repositories/ExchangeProgressRepository"; import ExchangeProgressUseCase from "../../domain/usecases/ExchangeProgressUseCase"; -export default class ExchangeProgressUseCaseImpl - implements ExchangeProgressUseCase -{ - constructor( - private exchangeProgressRepository: ExchangeProgressRepository - ) {} - getExchangeProgress( +export default class ExchangeProgressUseCaseImpl implements ExchangeProgressUseCase { + constructor(private exchangeProgressRepository: ExchangeProgressRepository) { + } + + async getExchangeProgress( exchangeDescriptor: VCLExchangeDescriptor - ): Promise> { - return this.exchangeProgressRepository.getExchangeProgress( - exchangeDescriptor - ); + ): Promise { + try { + return await this.exchangeProgressRepository.getExchangeProgress(exchangeDescriptor); + } catch (error: any) { + throw new Error(error); + } } } diff --git a/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts index 89f634c..d8d2e32 100644 --- a/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts @@ -1,79 +1,45 @@ -import { Nullish } from "../../../api/VCLTypes"; -import VCLError from "../../../api/entities/error/VCLError"; -import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLFinalizeOffersDescriptor from "../../../api/entities/VCLFinalizeOffersDescriptor"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtVerifiableCredentials from "../../../api/entities/VCLJwtVerifiableCredentials"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLToken from "../../../api/entities/VCLToken"; import FinalizeOffersRepository from "../../domain/repositories/FinalizeOffersRepository"; import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository"; import FinalizeOffersUseCase from "../../domain/usecases/FinalizeOffersUseCase"; export default class FinalizeOffersUseCaseImpl - implements FinalizeOffersUseCase -{ + implements FinalizeOffersUseCase { constructor( private finalizeOffersRepository: FinalizeOffersRepository, private jwtServiceRepository: JwtServiceRepository - ) {} + ) { + } + async finalizeOffers( - token: VCLToken, - finalizeOffersDescriptor: VCLFinalizeOffersDescriptor - ): Promise> { + finalizeOffersDescriptor: VCLFinalizeOffersDescriptor, + sessionToken: VCLToken, + ): Promise { const passedCredentials: VCLJwt[] = []; const failedCredentials: VCLJwt[] = []; - - const encodedJwtOffersListResult = - await this.finalizeOffersRepository.finalizeOffers( - token, - finalizeOffersDescriptor - ); - const [error, encodedJwtOffers] = encodedJwtOffersListResult.handleResult(); - - if (error) { - return new VCLResult.Error(error); - } - - for (const encodedJwtOffer of encodedJwtOffers!) { - const jwtResult = await this.jwtServiceRepository.decode( - encodedJwtOffer + try { + const jwtCredentialsList = await this.finalizeOffersRepository.finalizeOffers( + finalizeOffersDescriptor, + sessionToken, ); - const [error, jwt] = jwtResult.handleResult(); - if (error) { - return new VCLResult.Error(error); - } - if (!jwt) { - return new VCLResult.Error( - new VCLError("Error occured while parsing jwt.") - ); - } - - if (this.verifyJwtCredential(jwt, finalizeOffersDescriptor)) { - passedCredentials.push(jwt); - } else { - failedCredentials.push(jwt); - } - - if ( - encodedJwtOffers!.length == - passedCredentials.length + failedCredentials.length - ) { - return new VCLResult.Success( - new VCLJwtVerifiableCredentials( - passedCredentials, - failedCredentials - ) - ); + for (const jwtCredential of jwtCredentialsList) { + if (this.verifyJwtCredential(jwtCredential, finalizeOffersDescriptor)) { + passedCredentials.push(jwtCredential); + } else { + failedCredentials.push(jwtCredential); + } + + if (jwtCredentialsList.length == passedCredentials.length + failedCredentials.length) { + return new VCLJwtVerifiableCredentials(passedCredentials, failedCredentials); + } } + return new VCLJwtVerifiableCredentials(passedCredentials, failedCredentials); + } catch (error: any) { + throw new Error(error); } - - return new VCLResult.Success( - new VCLJwtVerifiableCredentials( - passedCredentials, - failedCredentials - ) - ); } private verifyJwtCredential( diff --git a/packages/sdk/src/impl/data/usecases/GenerateOffersUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/GenerateOffersUseCaseImpl.ts index 67e9c08..e8bba72 100644 --- a/packages/sdk/src/impl/data/usecases/GenerateOffersUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/GenerateOffersUseCaseImpl.ts @@ -1,6 +1,5 @@ import VCLGenerateOffersDescriptor from "../../../api/entities/VCLGenerateOffersDescriptor"; import VCLOffers from "../../../api/entities/VCLOffers"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLToken from "../../../api/entities/VCLToken"; import GenerateOffersRepository from "../../domain/repositories/GenerateOffersRepository"; import GenerateOffersUseCase from "../../domain/usecases/GenerateOffersUseCase"; @@ -11,12 +10,13 @@ export default class GenerateOffersUseCaseImpl constructor(private generateOffersRepository: GenerateOffersRepository) {} async generateOffers( - token: VCLToken, - generateOffersDescriptor: VCLGenerateOffersDescriptor - ): Promise> { - return this.generateOffersRepository.generateOffers( - token, - generateOffersDescriptor - ); + generateOffersDescriptor: VCLGenerateOffersDescriptor, + sessionToken: VCLToken + ): Promise { + try { + return await this.generateOffersRepository.generateOffers(generateOffersDescriptor, sessionToken); + } catch (error: any) { + throw new Error(error); + } } } diff --git a/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts index 8c4f38d..eb72609 100644 --- a/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts @@ -1,9 +1,7 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; -import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository"; import JwtServiceUseCase from "../../domain/usecases/JwtServiceUseCase"; import { Nullish } from "../../../api/VCLTypes"; @@ -12,19 +10,24 @@ import VCLToken from "../../../api/entities/VCLToken"; export default class JwtServiceUseCaseImpl implements JwtServiceUseCase { constructor(private readonly jwtServiceRepository: JwtServiceRepository) {} - verifyJwt( + async verifyJwt( jwt: VCLJwt, publicJwk: Nullish, remoteCryptoServicesToken: Nullish ) { - return this.jwtServiceRepository.verifyJwt(jwt, publicJwk, remoteCryptoServicesToken); + try { + return await this.jwtServiceRepository.verifyJwt(jwt, publicJwk, remoteCryptoServicesToken); + } catch (error: any) { + throw new Error(error); + } } - generateSignedJwt( + + async generateSignedJwt( jwtDescriptor: VCLJwtDescriptor, didJwk: VCLDidJwk, nonce: Nullish, remoteCryptoServicesToken: Nullish - ): Promise> { + ): Promise { return this.jwtServiceRepository.generateSignedJwt(jwtDescriptor, didJwk, nonce, remoteCryptoServicesToken); } } diff --git a/packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts index e7fc3eb..497d337 100644 --- a/packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts @@ -1,14 +1,17 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import KeyServiceRepository from "../../domain/repositories/KeyServiceRepository"; import KeyServiceUseCase from "../../domain/usecases/KeyServiceUseCase"; export default class KeyServiceUseCaseImpl implements KeyServiceUseCase { constructor(private readonly keyServiceRepository: KeyServiceRepository) {} - generateDidJwk( + async generateDidJwk( didJwkDescriptor: VCLDidJwkDescriptor - ): Promise> { - return this.keyServiceRepository.generateDidJwk(didJwkDescriptor); + ): Promise { + try { + return await this.keyServiceRepository.generateDidJwk(didJwkDescriptor); + } catch (error: any) { + throw new Error(error); + } } } diff --git a/packages/sdk/src/impl/data/usecases/OrganizationsUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/OrganizationsUseCaseImpl.ts index decc4d9..bd6b007 100644 --- a/packages/sdk/src/impl/data/usecases/OrganizationsUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/OrganizationsUseCaseImpl.ts @@ -1,17 +1,18 @@ import VCLOrganizations from "../../../api/entities/VCLOrganizations"; import VCLOrganizationsSearchDescriptor from "../../../api/entities/VCLOrganizationsSearchDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import OrganizationsRepository from "../../domain/repositories/OrganizationsRepository"; import OrganizationsUseCase from "../../domain/usecases/OrganizationsUseCase"; export default class OrganizationsUseCaseImpl implements OrganizationsUseCase { constructor(private organizationsRepository: OrganizationsRepository) {} - searchForOrganizations( + async searchForOrganizations( organizationsSearchDescriptor: VCLOrganizationsSearchDescriptor - ): Promise> { - return this.organizationsRepository.searchForOrganizations( - organizationsSearchDescriptor - ); + ): Promise { + try { + return await this.organizationsRepository.searchForOrganizations(organizationsSearchDescriptor); + } catch (error: any) { + throw new Error(error); + } } } diff --git a/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts index e841e5b..13a7f34 100644 --- a/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts @@ -3,45 +3,31 @@ import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLPresentationRequest from "../../../api/entities/VCLPresentationRequest"; import VCLPresentationRequestDescriptor from "../../../api/entities/VCLPresentationRequestDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository"; import PresentationRequestRepository from "../../domain/repositories/PresentationRequestRepository"; import ResolveKidRepository from "../../domain/repositories/ResolveKidRepository"; import PresentationRequestUseCase from "../../domain/usecases/PresentationRequestUseCase"; import VCLVerifiedProfile from "../../../api/entities/VCLVerifiedProfile"; -import { Nullish } from "../../../api/VCLTypes"; -import VCLToken from "../../../api/entities/VCLToken"; export default class PresentationRequestUseCaseImpl - implements PresentationRequestUseCase -{ + implements PresentationRequestUseCase { constructor( private presentationRequestRepository: PresentationRequestRepository, private resolveKidRepository: ResolveKidRepository, private jwtServiceRepository: JwtServiceRepository - ) {} + ) { + } async getPresentationRequest( presentationRequestDescriptor: VCLPresentationRequestDescriptor, verifiedProfile: VCLVerifiedProfile - ): Promise> { - const encodedJwtStrResult = - await this.presentationRequestRepository.getPresentationRequest( - presentationRequestDescriptor - ); - - const [error, encodedJwtStr] = encodedJwtStrResult.handleResult(); - if (error) { - return new VCLResult.Error(error); - } + ): Promise { try { - const jwtResult = await this.jwtServiceRepository.decode( - encodedJwtStr ?? '' - ); - const [error, jwt] = jwtResult.handleResult(); - if (error) { - return this.onError(error); - } + const encodedJwtStr = + await this.presentationRequestRepository.getPresentationRequest( + presentationRequestDescriptor + ); + const jwt = await this.jwtServiceRepository.decode(encodedJwtStr); return this.onGetPresentationRequestSuccess( new VCLPresentationRequest( jwt as VCLJwt, @@ -53,66 +39,41 @@ export default class PresentationRequestUseCaseImpl ), ); } catch (error: any) { - return this.onError(new VCLError(error)); + throw new Error(error); } } async onGetPresentationRequestSuccess( presentationRequest: VCLPresentationRequest - ): Promise> { + ): Promise { const kid = presentationRequest.jwt.kid?.replace("#", encodeURIComponent("#")); if (!kid) { - return this.onError(new VCLError("Empty kid")); - } - const publicJwkResult = await this.resolveKidRepository.getPublicKey( - kid - ); - - const [error, publicJwk] = publicJwkResult.handleResult(); - - if (error) { - return this.onError(error); + throw new VCLError("Empty kid"); } - - return this.onResolvePublicKeySuccess( - publicJwk as VCLPublicJwk, - presentationRequest - ); + const publicJwk = await this.resolveKidRepository.getPublicKey(kid); + return this.onResolvePublicKeySuccess(publicJwk, presentationRequest); } async onResolvePublicKeySuccess( publicJwk: VCLPublicJwk, presentationRequest: VCLPresentationRequest - ): Promise> { - const isVerifiedResult = await this.jwtServiceRepository.verifyJwt( + ): Promise { + const isVerified = await this.jwtServiceRepository.verifyJwt( presentationRequest.jwt, publicJwk, presentationRequest.remoteCryptoServicesToken ); - const [error, isVerified] = isVerifiedResult.handleResult(); - - if (error) { - return this.onError(error); - } - return this.onVerificationSuccess(isVerified!, presentationRequest); + return this.onVerificationSuccess(isVerified, presentationRequest); } async onVerificationSuccess( isVerified: boolean, presentationRequest: VCLPresentationRequest - ): Promise> { + ): Promise { if (isVerified) { - return new VCLResult.Success(presentationRequest); + return presentationRequest; } else { - return this.onError( - new VCLError( - `Failed to verify: ${presentationRequest.jwt.payload}` - ) - ); + throw new VCLError(`Failed to verify: ${presentationRequest.jwt.payload}`); } } - - onError(error: VCLError): VCLResult { - return new VCLResult.Error(error); - } } diff --git a/packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts index aa19761..9d3660d 100644 --- a/packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts @@ -1,7 +1,4 @@ -import { Nullish } from "../../../api/VCLTypes"; -import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLSubmission from "../../../api/entities/VCLSubmission"; import VCLSubmissionResult from "../../../api/entities/VCLSubmissionResult"; import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository"; @@ -12,30 +9,26 @@ export default class SubmissionUseCaseImpl implements SubmissionUseCase { constructor( private submissionRepository: SubmissionRepository, private jwtServiceRepository: JwtServiceRepository - ) {} + ) { + } + async submit( submission: VCLSubmission - ): Promise> { - const signedJwtResult = await this.jwtServiceRepository.generateSignedJwt( - new VCLJwtDescriptor( - submission.generatePayload(), - submission.iss, - submission.jti, - submission.didJwk?.keyId - ), - submission.didJwk, - null, - submission.remoteCryptoServicesToken - ); - - const [error, jwt] = signedJwtResult.handleResult(); - - if (error) { - return new VCLResult.Error(error); + ): Promise { + try { + const jwt = await this.jwtServiceRepository.generateSignedJwt( + new VCLJwtDescriptor( + submission.generatePayload(submission.didJwk.did), + submission.jti, + submission.didJwk.did, + ), + submission.didJwk, + null, + submission.remoteCryptoServicesToken + ); + return await this.submissionRepository.submit(submission, jwt); + } catch (error: any) { + throw new Error(error); } - return await this.submissionRepository.submit( - submission, - jwt! - ); } } diff --git a/packages/sdk/src/impl/data/usecases/VerifiedProfileUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/VerifiedProfileUseCaseImpl.ts index d5e0e09..8650de8 100644 --- a/packages/sdk/src/impl/data/usecases/VerifiedProfileUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/VerifiedProfileUseCaseImpl.ts @@ -1,21 +1,19 @@ -import VCLResult from "../../../api/entities/VCLResult"; -import VCLVerifiedProfile from "../../../api/entities/VCLVerifiedProfile"; import VCLVerifiedProfileDescriptor from "../../../api/entities/VCLVerifiedProfileDescriptor"; import VerifiedProfileRepository from "../../domain/repositories/VerifiedProfileRepository"; import VerifiedProfileUseCase from "../../domain/usecases/VerifiedProfileUseCase"; export default class VerifiedProfileUseCaseImpl - implements VerifiedProfileUseCase -{ + implements VerifiedProfileUseCase { constructor( private readonly verifiedProfileRepository: VerifiedProfileRepository - ) {} - - getVerifiedProfile( - verifiedProfileDescriptor: VCLVerifiedProfileDescriptor ) { - return this.verifiedProfileRepository.getVerifiedProfile( - verifiedProfileDescriptor - ); + } + + async getVerifiedProfile(verifiedProfileDescriptor: VCLVerifiedProfileDescriptor) { + try { + return await this.verifiedProfileRepository.getVerifiedProfile(verifiedProfileDescriptor); + } catch (error: any) { + throw new Error(error); + } } } diff --git a/packages/sdk/src/impl/domain/infrastructure/jwt/JwtService.ts b/packages/sdk/src/impl/domain/infrastructure/jwt/JwtService.ts deleted file mode 100644 index 6976bcd..0000000 --- a/packages/sdk/src/impl/domain/infrastructure/jwt/JwtService.ts +++ /dev/null @@ -1,20 +0,0 @@ -import VCLDidJwk from "../../../../api/entities/VCLDidJwk"; -import VCLDidJwkDescriptor from "../../../../api/entities/VCLDidJwkDescriptor"; -import VCLJwt, { SignedJWT } from "../../../../api/entities/VCLJwt"; -import VCLJwtDescriptor from "../../../../api/entities/VCLJwtDescriptor"; -import VCLResult from "../../../../api/entities/VCLResult"; -/* -export default interface JwtService { - parse(jwt: string): Nullish; - - encode(str: string): string; - - verify(jwt: VCLJwt, jwk: string): Promise; - - sign(jwtDescriptor: VCLJwtDescriptor): Promise>; - - generateDidJwk( - didJwkDescriptor: Nullish - ): Promise; -} - */ diff --git a/packages/sdk/src/impl/domain/infrastructure/network/NetworkService.ts b/packages/sdk/src/impl/domain/infrastructure/network/NetworkService.ts index 8d89823..4969a2d 100644 --- a/packages/sdk/src/impl/domain/infrastructure/network/NetworkService.ts +++ b/packages/sdk/src/impl/domain/infrastructure/network/NetworkService.ts @@ -1,11 +1,10 @@ import { Nullish } from "../../../../api/VCLTypes"; -import VCLResult from "../../../../api/entities/VCLResult"; import Request, { HttpMethod, } from "../../../data/infrastructure/network/Request"; import Response from "../../../data/infrastructure/network/Response"; -type NetworkRequesParams = { +type NetworkRequestParams = { endpoint: string; body: Nullish; contentType: Nullish; @@ -15,7 +14,7 @@ type NetworkRequesParams = { }; export default interface NetworkService { - sendRequestRaw(params: Request): Promise>; + sendRequestRaw(params: Request): Promise; - sendRequest(params: NetworkRequesParams): Promise>; + sendRequest(params: NetworkRequestParams): Promise; } diff --git a/packages/sdk/src/impl/domain/models/IdentificationModel.ts b/packages/sdk/src/impl/domain/models/IdentificationModel.ts index 34fd65b..15067dc 100644 --- a/packages/sdk/src/impl/domain/models/IdentificationModel.ts +++ b/packages/sdk/src/impl/domain/models/IdentificationModel.ts @@ -1,6 +1,5 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLIdentificationSubmission from "../../../api/entities/VCLIdentificationSubmission"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLSubmissionResult from "../../../api/entities/VCLSubmissionResult"; import VCLToken from "../../../api/entities/VCLToken"; import Model from "./Model"; @@ -8,7 +7,6 @@ import Model from "./Model"; export default interface IdentificationModel extends Model { submit( identificationSubmission: VCLIdentificationSubmission, - didJwk: VCLDidJwk, - completionBlock: (r: VCLResult) => any - ): void; + didJwk: VCLDidJwk + ): Promise; } diff --git a/packages/sdk/src/impl/domain/models/Initializable.ts b/packages/sdk/src/impl/domain/models/Initializable.ts index 5b19173..dcd4345 100644 --- a/packages/sdk/src/impl/domain/models/Initializable.ts +++ b/packages/sdk/src/impl/domain/models/Initializable.ts @@ -1,6 +1,6 @@ import VCLError from "../../../api/entities/error/VCLError"; -import VCLResult from "../../../api/entities/VCLResult"; +// eslint-disable-next-line export default interface Initializable { initialize(): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/CountriesRepository.ts b/packages/sdk/src/impl/domain/repositories/CountriesRepository.ts index 7d6f5a6..29447bb 100644 --- a/packages/sdk/src/impl/domain/repositories/CountriesRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/CountriesRepository.ts @@ -1,6 +1,5 @@ -import VCLResult from "../../../api/entities/VCLResult"; import VCLCountries from "../../../api/entities/VCLCountries"; export default interface CountriesRepository { - getCountries(): Promise>; + getCountries(): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/CredentialManifestRepository.ts b/packages/sdk/src/impl/domain/repositories/CredentialManifestRepository.ts index 7420f7e..e1ce787 100644 --- a/packages/sdk/src/impl/domain/repositories/CredentialManifestRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/CredentialManifestRepository.ts @@ -1,8 +1,7 @@ -import VCLResult from "../../../api/entities/VCLResult"; import VCLCredentialManifestDescriptor from "../../../api/entities/VCLCredentialManifestDescriptor"; export default interface CredentialManifestRepository { getCredentialManifest( credentialManifestDescriptor: VCLCredentialManifestDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/CredentialTypeSchemaRepository.ts b/packages/sdk/src/impl/domain/repositories/CredentialTypeSchemaRepository.ts index 612254d..d236ae8 100644 --- a/packages/sdk/src/impl/domain/repositories/CredentialTypeSchemaRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/CredentialTypeSchemaRepository.ts @@ -1,8 +1,7 @@ import VCLCredentialTypeSchema from "../../../api/entities/VCLCredentialTypeSchema"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface CredentialTypeSchemaRepository { getCredentialTypeSchema( schemaName: string - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/CredentialTypesRepository.ts b/packages/sdk/src/impl/domain/repositories/CredentialTypesRepository.ts index d3c39d1..d141cb0 100644 --- a/packages/sdk/src/impl/domain/repositories/CredentialTypesRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/CredentialTypesRepository.ts @@ -1,8 +1,5 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface CredentialTypesRepository { - getCredentialTypes(): Promise>; + getCredentialTypes(): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/CredentialTypesUIFormSchemaRepository.ts b/packages/sdk/src/impl/domain/repositories/CredentialTypesUIFormSchemaRepository.ts index 93d2eee..9701c38 100644 --- a/packages/sdk/src/impl/domain/repositories/CredentialTypesUIFormSchemaRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/CredentialTypesUIFormSchemaRepository.ts @@ -1,13 +1,10 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLCountries from "../../../api/entities/VCLCountries"; import VCLCredentialTypesUIFormSchema from "../../../api/entities/VCLCredentialTypesUIFormSchema"; import VCLCredentialTypesUIFormSchemaDescriptor from "../../../api/entities/VCLCredentialTypesUIFormSchemaDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface CredentialTypesUIFormSchemaRepository { getCredentialTypesUIFormSchema( credentialTypesUIFormSchemaDescriptor: VCLCredentialTypesUIFormSchemaDescriptor, countries: VCLCountries - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/ExchangeProgressRepository.ts b/packages/sdk/src/impl/domain/repositories/ExchangeProgressRepository.ts index 887a4fe..bab6b58 100644 --- a/packages/sdk/src/impl/domain/repositories/ExchangeProgressRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/ExchangeProgressRepository.ts @@ -1,11 +1,8 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLExchange from "../../../api/entities/VCLExchange"; import VCLExchangeDescriptor from "../../../api/entities/VCLExchangeDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface ExchangeProgressRepository { getExchangeProgress( exchangeDescriptor: VCLExchangeDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/FinalizeOffersRepository.ts b/packages/sdk/src/impl/domain/repositories/FinalizeOffersRepository.ts index d48c028..5c2a15f 100644 --- a/packages/sdk/src/impl/domain/repositories/FinalizeOffersRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/FinalizeOffersRepository.ts @@ -1,13 +1,10 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLFinalizeOffersDescriptor from "../../../api/entities/VCLFinalizeOffersDescriptor"; -import VCLJwt from "../../../api/entities/VCLJwt"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLToken from "../../../api/entities/VCLToken"; +import VCLJwt from "../../../api/entities/VCLJwt"; export default interface FinalizeOffersRepository { finalizeOffers( - token: VCLToken, - finalizeOffersDescriptor: VCLFinalizeOffersDescriptor - ): Promise>; + finalizeOffersDescriptor: VCLFinalizeOffersDescriptor, + sessionToken: VCLToken + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/GenerateOffersRepository.ts b/packages/sdk/src/impl/domain/repositories/GenerateOffersRepository.ts index d04617a..ba0a817 100644 --- a/packages/sdk/src/impl/domain/repositories/GenerateOffersRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/GenerateOffersRepository.ts @@ -1,11 +1,10 @@ import VCLGenerateOffersDescriptor from "../../../api/entities/VCLGenerateOffersDescriptor"; import VCLOffers from "../../../api/entities/VCLOffers"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLToken from "../../../api/entities/VCLToken"; export default interface GenerateOffersRepository { generateOffers( - token: VCLToken, - generateOffersDescriptor: VCLGenerateOffersDescriptor - ): Promise>; + generateOffersDescriptor: VCLGenerateOffersDescriptor, + sessionToken: VCLToken + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/JwtServiceRepository.ts b/packages/sdk/src/impl/domain/repositories/JwtServiceRepository.ts index 1f14fc7..fe4ce41 100644 --- a/packages/sdk/src/impl/domain/repositories/JwtServiceRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/JwtServiceRepository.ts @@ -1,28 +1,23 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLDidJwk from "../../../api/entities/VCLDidJwk"; -import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import { Nullish } from "../../../api/VCLTypes"; -import VCLSignatureAlgorithm from "../../../api/VCLSignatureAlgorithm"; import VCLToken from "../../../api/entities/VCLToken"; export default interface JwtServiceRepository { - decode(encodedJwt: string): Promise>; + decode(encodedJwt: string): Promise; verifyJwt( jwt: VCLJwt, publicJwk: Nullish, remoteCryptoServicesToken: Nullish - ): Promise>; + ): Promise; generateSignedJwt( jwtDescriptor: VCLJwtDescriptor, didJwk: VCLDidJwk, nonce: Nullish, remoteCryptoServicesToken: Nullish - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/KeyServiceRepository.ts b/packages/sdk/src/impl/domain/repositories/KeyServiceRepository.ts index 86a15d7..84c6272 100644 --- a/packages/sdk/src/impl/domain/repositories/KeyServiceRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/KeyServiceRepository.ts @@ -1,11 +1,8 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface KeyServiceRepository { generateDidJwk( didJwkDescriptor: VCLDidJwkDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/OrganizationsRepository.ts b/packages/sdk/src/impl/domain/repositories/OrganizationsRepository.ts index 1a692c1..c91aea6 100644 --- a/packages/sdk/src/impl/domain/repositories/OrganizationsRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/OrganizationsRepository.ts @@ -1,11 +1,8 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLOrganizations from "../../../api/entities/VCLOrganizations"; import VCLOrganizationsSearchDescriptor from "../../../api/entities/VCLOrganizationsSearchDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface OrganizationsRepository { searchForOrganizations( organizationsSearchDescriptor: VCLOrganizationsSearchDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/PresentationRequestRepository.ts b/packages/sdk/src/impl/domain/repositories/PresentationRequestRepository.ts index 838b2a6..90d6030 100644 --- a/packages/sdk/src/impl/domain/repositories/PresentationRequestRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/PresentationRequestRepository.ts @@ -1,10 +1,7 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLPresentationRequestDescriptor from "../../../api/entities/VCLPresentationRequestDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface PresentationRequestRepository { getPresentationRequest( presentationRequestDescriptor: VCLPresentationRequestDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/ResolveKidRepository.ts b/packages/sdk/src/impl/domain/repositories/ResolveKidRepository.ts index 332998b..404ffb5 100644 --- a/packages/sdk/src/impl/domain/repositories/ResolveKidRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/ResolveKidRepository.ts @@ -1,8 +1,5 @@ -// package io.velocitycareerlabs.impl.domain.repositories - 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/repositories/SubmissionRepository.ts b/packages/sdk/src/impl/domain/repositories/SubmissionRepository.ts index bd6c701..8ba7907 100644 --- a/packages/sdk/src/impl/domain/repositories/SubmissionRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/SubmissionRepository.ts @@ -1,7 +1,4 @@ -// package io.velocitycareerlabs.impl.domain.repositories - import VCLJwt from "../../../api/entities/VCLJwt"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLSubmission from "../../../api/entities/VCLSubmission"; import VCLSubmissionResult from "../../../api/entities/VCLSubmissionResult"; @@ -9,5 +6,5 @@ export default interface SubmissionRepository { submit( submission: VCLSubmission, jwt: VCLJwt - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/repositories/VerifiedProfileRepository.ts b/packages/sdk/src/impl/domain/repositories/VerifiedProfileRepository.ts index d2cda74..cf0eeed 100644 --- a/packages/sdk/src/impl/domain/repositories/VerifiedProfileRepository.ts +++ b/packages/sdk/src/impl/domain/repositories/VerifiedProfileRepository.ts @@ -1,9 +1,7 @@ -import VCLResult from "../../../api/entities/VCLResult"; import VCLVerifiedProfile from "../../../api/entities/VCLVerifiedProfile"; import VCLVerifiedProfileDescriptor from "../../../api/entities/VCLVerifiedProfileDescriptor"; export default interface VerifiedProfileRepository { - getVerifiedProfile( - verifiedProfileDescriptor: VCLVerifiedProfileDescriptor - ): Promise>; + getVerifiedProfile(verifiedProfileDescriptor: VCLVerifiedProfileDescriptor): Promise; + } diff --git a/packages/sdk/src/impl/domain/usecases/CountriesModelUseCase.ts b/packages/sdk/src/impl/domain/usecases/CountriesModelUseCase.ts index 3b5ec31..c6702b9 100644 --- a/packages/sdk/src/impl/domain/usecases/CountriesModelUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/CountriesModelUseCase.ts @@ -1,6 +1,5 @@ import VCLCountries from "../../../api/entities/VCLCountries"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface CountriesUseCase { - getCountries(): Promise>; + getCountries(): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/CredentialManifestUseCase.ts b/packages/sdk/src/impl/domain/usecases/CredentialManifestUseCase.ts index b4fbb82..9715fff 100644 --- a/packages/sdk/src/impl/domain/usecases/CredentialManifestUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/CredentialManifestUseCase.ts @@ -1,12 +1,10 @@ import VCLCredentialManifest from "../../../api/entities/VCLCredentialManifest"; import VCLCredentialManifestDescriptor from "../../../api/entities/VCLCredentialManifestDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; -import VCLToken from "../../../api/entities/VCLToken"; import VCLVerifiedProfile from "../../../api/entities/VCLVerifiedProfile"; export default interface CredentialManifestUseCase { getCredentialManifest( credentialManifestDescriptor: VCLCredentialManifestDescriptor, verifiedProfile: VCLVerifiedProfile - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/CredentialTypeSchemasUseCase.ts b/packages/sdk/src/impl/domain/usecases/CredentialTypeSchemasUseCase.ts index a9c0ff3..146ef01 100644 --- a/packages/sdk/src/impl/domain/usecases/CredentialTypeSchemasUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/CredentialTypeSchemasUseCase.ts @@ -1,14 +1,5 @@ -/* -internal interface CredentialTypeSchemasUseCase { - fun getCredentialTypeSchemas( - cacheSequence: Int, - completionBlock:(VCLResult) -> Unit - ) -}*/ - import VCLCredentialTypeSchemas from "../../../api/entities/VCLCredentialTypeSchemas"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface CredentialTypeSchemasUseCase { - getCredentialTypeSchemas(): Promise>; + getCredentialTypeSchemas(): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/CredentialTypesUIFormSchemaUseCase.ts b/packages/sdk/src/impl/domain/usecases/CredentialTypesUIFormSchemaUseCase.ts index 1323a44..b2f8d36 100644 --- a/packages/sdk/src/impl/domain/usecases/CredentialTypesUIFormSchemaUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/CredentialTypesUIFormSchemaUseCase.ts @@ -1,19 +1,10 @@ -/*internal interface CredentialTypesUIFormSchemaUseCase { - fun getCredentialTypesUIFormSchema( - credentialTypesUIFormSchemaDescriptor: VCLCredentialTypesUIFormSchemaDescriptor, - countries: VCLCountries, - completionBlock: (VCLResult) -> Unit - ) -}*/ - import VCLCountries from "../../../api/entities/VCLCountries"; import VCLCredentialTypesUIFormSchema from "../../../api/entities/VCLCredentialTypesUIFormSchema"; import VCLCredentialTypesUIFormSchemaDescriptor from "../../../api/entities/VCLCredentialTypesUIFormSchemaDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface CredentialTypesUIFormSchemaUseCase { getCredentialTypesUIFormSchema( credentialTypesUIFormSchemaDescriptor: VCLCredentialTypesUIFormSchemaDescriptor, countries: VCLCountries - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/CredentialTypesUseCase.ts b/packages/sdk/src/impl/domain/usecases/CredentialTypesUseCase.ts index 02a0cb7..753aa5b 100644 --- a/packages/sdk/src/impl/domain/usecases/CredentialTypesUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/CredentialTypesUseCase.ts @@ -1,6 +1,5 @@ import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; -import VCLResult from "../../../api/entities/VCLResult"; export interface CredentialTypesUseCase { - getCredentialTypes(): Promise>; + getCredentialTypes(): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/ExchangeProgressUseCase.ts b/packages/sdk/src/impl/domain/usecases/ExchangeProgressUseCase.ts index c26b914..3c507a6 100644 --- a/packages/sdk/src/impl/domain/usecases/ExchangeProgressUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/ExchangeProgressUseCase.ts @@ -1,9 +1,8 @@ import VCLExchange from "../../../api/entities/VCLExchange"; import VCLExchangeDescriptor from "../../../api/entities/VCLExchangeDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface ExchangeProgressUseCase { getExchangeProgress( exchangeDescriptor: VCLExchangeDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/FinalizeOffersUseCase.ts b/packages/sdk/src/impl/domain/usecases/FinalizeOffersUseCase.ts index b69accf..7db729b 100644 --- a/packages/sdk/src/impl/domain/usecases/FinalizeOffersUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/FinalizeOffersUseCase.ts @@ -1,13 +1,10 @@ -import { Nullish } from "../../../api/VCLTypes"; -import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLFinalizeOffersDescriptor from "../../../api/entities/VCLFinalizeOffersDescriptor"; import VCLJwtVerifiableCredentials from "../../../api/entities/VCLJwtVerifiableCredentials"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLToken from "../../../api/entities/VCLToken"; export default interface FinalizeOffersUseCase { finalizeOffers( - token: VCLToken, finalizeOffersDescriptor: VCLFinalizeOffersDescriptor, - ): Promise>; + sessionToken: VCLToken, + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/GenerateOffersUseCase.ts b/packages/sdk/src/impl/domain/usecases/GenerateOffersUseCase.ts index 8111660..9bc0c07 100644 --- a/packages/sdk/src/impl/domain/usecases/GenerateOffersUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/GenerateOffersUseCase.ts @@ -1,11 +1,10 @@ import VCLGenerateOffersDescriptor from "../../../api/entities/VCLGenerateOffersDescriptor"; import VCLOffers from "../../../api/entities/VCLOffers"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLToken from "../../../api/entities/VCLToken"; export default interface GenerateOffersUseCase { generateOffers( - token: VCLToken, - generateOffersDescriptor: VCLGenerateOffersDescriptor - ): Promise>; + generateOffersDescriptor: VCLGenerateOffersDescriptor, + sessionToken: VCLToken + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/JwtServiceUseCase.ts b/packages/sdk/src/impl/domain/usecases/JwtServiceUseCase.ts index 2782c77..b8b205d 100644 --- a/packages/sdk/src/impl/domain/usecases/JwtServiceUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/JwtServiceUseCase.ts @@ -1,9 +1,7 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; -import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; import VCLPublicJwk from "../../../api/entities/VCLPublicJwk"; import VCLJwt from "../../../api/entities/VCLJwt"; import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import { Nullish } from "../../../api/VCLTypes"; import VCLToken from "../../../api/entities/VCLToken"; @@ -12,12 +10,12 @@ export default interface JwtServiceUseCase { jwt: VCLJwt, publicJwk: Nullish, remoteCryptoServicesToken: Nullish - ): Promise>; + ): Promise; generateSignedJwt( jwtDescriptor: VCLJwtDescriptor, didJwk: VCLDidJwk, nonce: Nullish, remoteCryptoServicesToken: Nullish - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/KeyServiceUseCase.ts b/packages/sdk/src/impl/domain/usecases/KeyServiceUseCase.ts index dec602d..d175c56 100644 --- a/packages/sdk/src/impl/domain/usecases/KeyServiceUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/KeyServiceUseCase.ts @@ -1,9 +1,8 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface KeyServiceUseCase { generateDidJwk( didJwkDescriptor: VCLDidJwkDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/OrganizationsUseCase.ts b/packages/sdk/src/impl/domain/usecases/OrganizationsUseCase.ts index c3064d0..b777e3e 100644 --- a/packages/sdk/src/impl/domain/usecases/OrganizationsUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/OrganizationsUseCase.ts @@ -1,9 +1,8 @@ import VCLOrganizations from "../../../api/entities/VCLOrganizations"; import VCLOrganizationsSearchDescriptor from "../../../api/entities/VCLOrganizationsSearchDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; export default interface OrganizationsUseCase { searchForOrganizations( organizationsSearchDescriptor: VCLOrganizationsSearchDescriptor - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/PresentationRequestUseCase.ts b/packages/sdk/src/impl/domain/usecases/PresentationRequestUseCase.ts index 6ccd65c..6bda0ef 100644 --- a/packages/sdk/src/impl/domain/usecases/PresentationRequestUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/PresentationRequestUseCase.ts @@ -1,11 +1,10 @@ import VCLPresentationRequest from "../../../api/entities/VCLPresentationRequest"; import VCLPresentationRequestDescriptor from "../../../api/entities/VCLPresentationRequestDescriptor"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLVerifiedProfile from "../../../api/entities/VCLVerifiedProfile"; export default interface PresentationRequestUseCase { getPresentationRequest( presentationRequestDescriptor: VCLPresentationRequestDescriptor, verifiedProfile: VCLVerifiedProfile - ): Promise>; + ): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/SubmissionUseCase.ts b/packages/sdk/src/impl/domain/usecases/SubmissionUseCase.ts index da1465c..4d71f37 100644 --- a/packages/sdk/src/impl/domain/usecases/SubmissionUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/SubmissionUseCase.ts @@ -1,11 +1,6 @@ -import { Nullish } from "../../../api/VCLTypes"; -import VCLDidJwk from "../../../api/entities/VCLDidJwk"; -import VCLResult from "../../../api/entities/VCLResult"; import VCLSubmission from "../../../api/entities/VCLSubmission"; import VCLSubmissionResult from "../../../api/entities/VCLSubmissionResult"; export default interface SubmissionUseCase { - submit( - submission: VCLSubmission - ): Promise>; + submit(submission: VCLSubmission): Promise; } diff --git a/packages/sdk/src/impl/domain/usecases/VerifiedProfileUseCase.ts b/packages/sdk/src/impl/domain/usecases/VerifiedProfileUseCase.ts index 47e1480..4c1d655 100644 --- a/packages/sdk/src/impl/domain/usecases/VerifiedProfileUseCase.ts +++ b/packages/sdk/src/impl/domain/usecases/VerifiedProfileUseCase.ts @@ -1,9 +1,6 @@ -import VCLResult from "../../../api/entities/VCLResult"; import VCLVerifiedProfile from "../../../api/entities/VCLVerifiedProfile"; import VCLVerifiedProfileDescriptor from "../../../api/entities/VCLVerifiedProfileDescriptor"; export default interface VerifiedProfileUseCase { - getVerifiedProfile( - verifiedProfileDescriptor: VCLVerifiedProfileDescriptor - ): Promise>; + getVerifiedProfile(verifiedProfileDescriptor: VCLVerifiedProfileDescriptor): Promise; } diff --git a/packages/sdk/src/impl/extensions/StringExtensions.ts b/packages/sdk/src/impl/extensions/StringExtensions.ts index afe9232..3607818 100644 --- a/packages/sdk/src/impl/extensions/StringExtensions.ts +++ b/packages/sdk/src/impl/extensions/StringExtensions.ts @@ -1,6 +1,5 @@ import { randomBytes } from "crypto"; import VCLLog from "../utils/VCLLog"; -import { Dictionary } from "../../api/VCLTypes"; String.prototype.getQueryParameters = function (): Map { const result = new Map(); diff --git a/packages/sdk/src/impl/utils/ProfileServiceTypeVerifier.ts b/packages/sdk/src/impl/utils/ProfileServiceTypeVerifier.ts index b63e048..c8d0e92 100644 --- a/packages/sdk/src/impl/utils/ProfileServiceTypeVerifier.ts +++ b/packages/sdk/src/impl/utils/ProfileServiceTypeVerifier.ts @@ -1,39 +1,47 @@ import VCLError from "../../api/entities/error/VCLError"; -import VCLResult from "../../api/entities/VCLResult"; import VCLServiceTypes from "../../api/entities/VCLServiceTypes"; 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"; +import { Dictionary, Nullish } from "../../api/VCLTypes"; export class ProfileServiceTypeVerifier { constructor( private readonly verifiedProfileUseCase: VerifiedProfileUseCase - ) {} + ) { + } async verifyServiceTypeOfVerifiedProfile( verifiedProfileDescriptor: VCLVerifiedProfileDescriptor, expectedServiceTypes: VCLServiceTypes - ): Promise> { - const verifiedProfileResult = - await this.verifiedProfileUseCase.getVerifiedProfile( - verifiedProfileDescriptor - ); - const [err, verifiedProfile] = verifiedProfileResult.handleResult(); + ): Promise { + const verifiedProfile = + await this.verifiedProfileUseCase.getVerifiedProfile(verifiedProfileDescriptor); - if (err) { - throw err; - } + await this.verifyServiceType(verifiedProfile, expectedServiceTypes); - const isVerified = await this.verifyServiceType( - verifiedProfile!, - expectedServiceTypes - ); + return verifiedProfile; + } - return new VCLResult.Success(verifiedProfile); + toJsonString(profileName: Nullish, message: Nullish): string { + try { + const jsonObject: Dictionary = {}; + if (profileName !== null) { + jsonObject.profileName = profileName; + } + if (message !== null) { + jsonObject.message = message; + } + return JSON.stringify(jsonObject); + } catch (e) { + console.error(e); + } + return `${profileName} ${message}`; } + async verifyServiceType( verifiedProfile: VCLVerifiedProfile, expectedServiceTypes: VCLServiceTypes @@ -46,14 +54,14 @@ export class ProfileServiceTypeVerifier { return true; } else { throw new VCLError( - JSON.stringify({ - profileName: verifiedProfile.name, - message: `Wrong service type - expected: ${expectedServiceTypes.all}, found: ${verifiedProfile.serviceTypes.all}`, - }), - VCLErrorCode.SdkError.toString(), null, + VCLErrorCode.SdkError.toString(), + this.toJsonString( + verifiedProfile.name, + `Wrong service type - expected: ${expectedServiceTypes.all}, found: ${verifiedProfile.serviceTypes.all}` + ), VCLStatusCode.VerificationError - ); + ) } } } diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 57d0cbe..79612f1 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -1,8 +1,8 @@ import VCLProvider from "./api/VCLProvider"; import VCLSignatureAlgorithm from "./api/VCLSignatureAlgorithm"; import VCL from "./api/VCL"; -import VCLInitializationDescriptor from "./api/entities/VCLInitializationDescriptor"; -import VCLCryptoServicesDescriptor from "./api/entities/VCLCryptoServicesDescriptor"; +import VCLInitializationDescriptor from "./api/entities/initialization/VCLInitializationDescriptor"; +import VCLCryptoServicesDescriptor from "./api/entities/initialization/VCLCryptoServicesDescriptor"; import VCLKeyService from "./api/keys/VCLKeyService"; import VCLJwtSignService from "./api/jwt/VCLJwtSignService"; import VCLJwtVerifyService from "./api/jwt/VCLJwtVerifyService"; @@ -56,7 +56,6 @@ import VCLDidJwk from "./api/entities/VCLDidJwk"; import VCLError from "./api/entities/error/VCLError"; import VCLStatusCode from "./api/entities/error/VCLStatusCode"; import VCLErrorCode from "./api/entities/error/VCLErrorCode"; -import VCLResult from "./api/entities/VCLResult"; import { Nullish, Dictionary } from "./api/VCLTypes"; export { @@ -119,7 +118,6 @@ export { VCLJwtDescriptor, VCLDidJwkDescriptor, VCLDidJwk, - VCLResult, Nullish, Dictionary, }; diff --git a/packages/sdk/test/NetworkServiceSuccess.ts b/packages/sdk/test/NetworkServiceSuccess.ts index ad75be6..060c147 100644 --- a/packages/sdk/test/NetworkServiceSuccess.ts +++ b/packages/sdk/test/NetworkServiceSuccess.ts @@ -1,15 +1,15 @@ +/* eslint-disable unused-imports/no-unused-vars,no-unused-vars */ import NetworkService from "../src/impl/domain/infrastructure/network/NetworkService"; -import VCLResult from "../src/api/entities/VCLResult"; import Request, { HttpMethod, } from "../src/impl/data/infrastructure/network/Request"; import Response from "../src/impl/data/infrastructure/network/Response"; -import { Dictionary, Nullish } from "../../sdk//src/api/VCLTypes"; +import { Nullish } from "../src"; export default class NetworkServiceSuccess implements NetworkService { constructor(private readonly validResponse: any) {} - sendRequestRaw(params: Request): Promise> { + sendRequestRaw(params: Request): Promise { throw new Error("not implemented"); } @@ -20,7 +20,7 @@ export default class NetworkServiceSuccess implements NetworkService { method: HttpMethod; headers: any; useCaches: boolean; - }): Promise> { - return new VCLResult.Success(new Response(this.validResponse, 0)); + }): Promise { + return new Response(this.validResponse, 0); } } diff --git a/packages/sdk/test/entities/VCLCredentialManifest.test.ts b/packages/sdk/test/entities/VCLCredentialManifest.test.ts new file mode 100644 index 0000000..1bc3d6b --- /dev/null +++ b/packages/sdk/test/entities/VCLCredentialManifest.test.ts @@ -0,0 +1,28 @@ +import { VCLCredentialManifest, VCLDeepLink, VCLJwt, VCLVerifiedProfile } from "../../src"; +import { CredentialManifestMocks } from "../infrastructure/resources/valid/CredentialManifestMocks"; +import { DidJwkMocks } from "../infrastructure/resources/valid/DidJwkMocks"; +import { expect } from "@jest/globals"; + +describe("VCLCredentialManifest Tests", () => { + + const subject: VCLCredentialManifest = new VCLCredentialManifest( + VCLJwt.fromEncodedJwt(CredentialManifestMocks.JwtCredentialManifest1), + null, + new VCLVerifiedProfile({}), + new VCLDeepLink(''), + DidJwkMocks.DidJwk + ) + test("VCLCredentialManifest props", () => { + + expect(subject.iss).toBe("did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA") + expect(subject.did).toBe("did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA") + expect(subject.issuerId).toBe("did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA") + expect(subject.aud).toBe("https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA") + expect(subject.exchangeId).toBe("645e315309237c760ac022b1") + expect(subject.presentationDefinitionId).toBe("645e315309237c760ac022b1.6384a3ad148b1991687f67c9") + expect(subject.finalizeOffersUri).toBe("https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA/issue/finalize-offers") + expect(subject.checkOffersUri).toBe("https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA/issue/credential-offers") + expect(subject.submitPresentationUri).toBe("https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA/issue/submit-identification") + }); + +}); \ No newline at end of file diff --git a/packages/sdk/test/entities/VCLError.test.ts b/packages/sdk/test/entities/VCLError.test.ts index 1b45f93..e695674 100644 --- a/packages/sdk/test/entities/VCLError.test.ts +++ b/packages/sdk/test/entities/VCLError.test.ts @@ -54,9 +54,6 @@ describe("VCLError Tests", () => { ); const errorJsonObject = error.jsonObject; - console.log("--------------------"); - console.log(JSON.stringify(errorJsonObject)); - expect(errorJsonObject[VCLError.KeyPayload]).toBeFalsy(); expect(errorJsonObject[VCLError.KeyError]).toBe(ErrorMocks.Error); expect(errorJsonObject[VCLError.KeyErrorCode]).toBe( diff --git a/packages/sdk/test/entities/VCLFinalizeOffersDescriptor.test.ts b/packages/sdk/test/entities/VCLFinalizeOffersDescriptor.test.ts new file mode 100644 index 0000000..573d313 --- /dev/null +++ b/packages/sdk/test/entities/VCLFinalizeOffersDescriptor.test.ts @@ -0,0 +1,64 @@ +import { + VCLCredentialManifest, + VCLDeepLink, + VCLFinalizeOffersDescriptor, + VCLJwt, + VCLOffers, + VCLToken, + VCLVerifiedProfile +} from "../../src"; +import { CredentialManifestMocks } from "../infrastructure/resources/valid/CredentialManifestMocks"; +import { DidJwkMocks } from "../infrastructure/resources/valid/DidJwkMocks"; +import { beforeAll, expect } from "@jest/globals"; +import { VerifiedProfileMocks } from "../infrastructure/resources/valid/VerifiedProfileMocks"; + +describe("VCLCredentialManifest Tests", () => { + + let subject: VCLFinalizeOffersDescriptor; + + const offers = new VCLOffers( + {}, + [], + 200, + new VCLToken(""), + "" + ) + const nonceMock = "some nonce" + + const approvedOfferIds = ["approvedOfferId1", "approvedOfferId2"] + const rejectedOfferIds = ["rejectedOfferId1", "rejectedOfferId2"] + + beforeAll(() => { + const credentialManifest = + new VCLCredentialManifest( + VCLJwt.fromEncodedJwt(CredentialManifestMocks.JwtCredentialManifest1), + null, + new VCLVerifiedProfile(JSON.parse(VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1)), + new VCLDeepLink(''), + DidJwkMocks.DidJwk + ) + subject = new VCLFinalizeOffersDescriptor( + credentialManifest, + offers, + approvedOfferIds, + rejectedOfferIds + ) + }); + + test("test generateRequest body", () => { + const jwtProof = VCLJwt.fromEncodedJwt( + 'eyJraWQiOiJkaWQ6andrOmV5SnJkSGtpT2lKRlF5SXNJblZ6WlNJNkluTnBaeUlzSW1OeWRpSTZJbEF0TWpVMklpd2lhMmxrSWpvaU56VXhOekZsWm1FdFkyTTRNaTAwWlRVeUxXSTFaVFl0WkRRMlpXRmhaamMzTkRneElpd2llQ0k2SW0xRldEbHliR2hJWVVaVmNreEtla0p4VWt4bmIySndNVmR4UzJSTmFEVndiVVp5UzJjME9WbEZkVUVpTENKNUlqb2lWakZPTVdKU1FrRXplalp2VGxrelZXdFFORUZsWVVGQk5rNUtiREl5TVRSVWFVSnFTRTlJYWpGdVVTSjkjMCIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2IiwiandrIjp7Imt0eSI6IkVDIiwidXNlIjoic2lnIiwiY3J2IjoiUC0yNTYiLCJraWQiOiI3NTE3MWVmYS1jYzgyLTRlNTItYjVlNi1kNDZlYWFmNzc0ODEiLCJ4IjoibUVYOXJsaEhhRlVyTEp6QnFSTGdvYnAxV3FLZE1oNXBtRnJLZzQ5WUV1QSIsInkiOiJWMU4xYlJCQTN6Nm9OWTNVa1A0QWVhQUE2TkpsMjIxNFRpQmpIT0hqMW5RIn19.eyJrZXkxIjoidmFsdWUxIiwiYXVkIjoic29tZSBzdWQiLCJzdWIiOiJ3VzdCZGhXNGNQIiwibmJmIjoxNzE2OTAzNzIxLCJpc3MiOiJzb21lIGlzcyIsImV4cCI6MTcxNzUwODUyMSwiaWF0IjoxNzE2OTAzNzIxLCJub25jZSI6InNvbWUgbm9uY2UiLCJqdGkiOiJzb21lIGp0aSJ9' + ) + const requestBody = subject.generateRequestBody(jwtProof) + + expect(requestBody["exchangeId"]).toBe("645e315309237c760ac022b1") + expect(requestBody["approvedOfferIds"]).toStrictEqual(approvedOfferIds) + expect(requestBody["rejectedOfferIds"]).toStrictEqual(rejectedOfferIds) + const proof = requestBody["proof"] + expect(proof["proof_type"]).toBe("jwt") + expect(proof["jwt"]).toBe(jwtProof.encodedJwt) +// equivalent to checking nonce in proof jwt + expect(jwtProof.payload["nonce"]).toBe(nonceMock) + }); + +}); \ No newline at end of file diff --git a/packages/sdk/test/entities/VCLJwt.test.ts b/packages/sdk/test/entities/VCLJwt.test.ts index 3ac4953..3f746c9 100644 --- a/packages/sdk/test/entities/VCLJwt.test.ts +++ b/packages/sdk/test/entities/VCLJwt.test.ts @@ -1,4 +1,4 @@ -import VCLJwt, { SignedJWT } from "../../src/api/entities/VCLJwt"; +import VCLJwt from "../../src/api/entities/VCLJwt"; import "../../src/impl/extensions/StringExtensions"; let subject: VCLJwt diff --git a/packages/sdk/test/entities/VCLSubmission.test.ts b/packages/sdk/test/entities/VCLSubmission.test.ts index a396016..33dfc73 100644 --- a/packages/sdk/test/entities/VCLSubmission.test.ts +++ b/packages/sdk/test/entities/VCLSubmission.test.ts @@ -17,7 +17,8 @@ describe("VCLSubmission Tests", () => { }); test("testPayload", () => { - expect(subject.payload[VCLSubmission.KeyJti]).toBe(subject.jti); + const payload = subject.generatePayload() + expect(payload[VCLSubmission.KeyJti]).toBe(subject.jti); }); test("testPushDelegate", () => { diff --git a/packages/sdk/test/infrastructure/resources/jwt/JwtSignServiceMock.ts b/packages/sdk/test/infrastructure/resources/jwt/JwtSignServiceMock.ts index 5d6729e..26cc860 100644 --- a/packages/sdk/test/infrastructure/resources/jwt/JwtSignServiceMock.ts +++ b/packages/sdk/test/infrastructure/resources/jwt/JwtSignServiceMock.ts @@ -1,19 +1,19 @@ +/* eslint-disable unused-imports/no-unused-vars,no-unused-vars */ import { Nullish, VCLJwtSignService } from "../../../../src"; import VCLJwtDescriptor from "../../../../src/api/entities/VCLJwtDescriptor"; import VCLDidJwk from "../../../../src/api/entities/VCLDidJwk"; -import VCLResult from "../../../../src/api/entities/VCLResult"; import VCLJwt from "../../../../src/api/entities/VCLJwt"; import VCLToken from "../../../../src/api/entities/VCLToken"; export class JwtSignServiceMock implements VCLJwtSignService { - constructor(readonly successValue: Nullish = null) { - } - sign( + constructor(readonly successValue: Nullish = null) {} + + async sign( jwtDescriptor: VCLJwtDescriptor, didJwk: VCLDidJwk, nonce: Nullish, remoteCryptoServicesToken: Nullish - ): Promise> { - return Promise.resolve(new VCLResult.Success(VCLJwt.fromEncodedJwt(this.successValue || ''))); + ): Promise { + return VCLJwt.fromEncodedJwt(this.successValue || ''); } } \ No newline at end of file diff --git a/packages/sdk/test/infrastructure/resources/jwt/JwtVerifyServiceMock.ts b/packages/sdk/test/infrastructure/resources/jwt/JwtVerifyServiceMock.ts index ee5937d..d45b658 100644 --- a/packages/sdk/test/infrastructure/resources/jwt/JwtVerifyServiceMock.ts +++ b/packages/sdk/test/infrastructure/resources/jwt/JwtVerifyServiceMock.ts @@ -1,7 +1,8 @@ -import { Nullish, VCLJwt, VCLJwtVerifyService, VCLPublicJwk, VCLResult } from "../../../../src"; +/* eslint-disable unused-imports/no-unused-vars,no-unused-vars */ +import { Nullish, VCLJwt, VCLJwtVerifyService, VCLPublicJwk } from "../../../../src"; export class JwtVerifyServiceMock implements VCLJwtVerifyService { - verify(jwt: VCLJwt, publicJwk: Nullish): Promise> { - return Promise.resolve(new VCLResult.Success(true)); + async verify(jwt: VCLJwt, publicJwk: Nullish): Promise { + return true; } } \ No newline at end of file diff --git a/packages/sdk/test/infrastructure/resources/key/KeyServiceMock.ts b/packages/sdk/test/infrastructure/resources/key/KeyServiceMock.ts index 26a8b01..bc30154 100644 --- a/packages/sdk/test/infrastructure/resources/key/KeyServiceMock.ts +++ b/packages/sdk/test/infrastructure/resources/key/KeyServiceMock.ts @@ -1,12 +1,11 @@ +/* eslint-disable unused-imports/no-unused-vars,no-unused-vars */ import { VCLKeyService } from "../../../../src"; import VCLDidJwkDescriptor from "../../../../src/api/entities/VCLDidJwkDescriptor"; -import VCLResult from "../../../../src/api/entities/VCLResult"; import VCLDidJwk from "../../../../src/api/entities/VCLDidJwk"; +import { DidJwkMocks } from "../valid/DidJwkMocks"; -class KeyServiceMock implements VCLKeyService { - generateDidJwk( - didJwkDescriptor: VCLDidJwkDescriptor - ): Promise> { - throw new Error("Method not implemented."); +export class KeyServiceMock implements VCLKeyService { + async generateDidJwk(didJwkDescriptor: VCLDidJwkDescriptor): Promise { + return DidJwkMocks.DidJwk } } \ No newline at end of file diff --git a/packages/sdk/test/infrastructure/resources/valid/CountriesMocks.ts b/packages/sdk/test/infrastructure/resources/valid/CountriesMocks.ts new file mode 100644 index 0000000..e303468 --- /dev/null +++ b/packages/sdk/test/infrastructure/resources/valid/CountriesMocks.ts @@ -0,0 +1,101 @@ +export class CountriesMocks { + static readonly AfghanistanRegion1Name: string = "Balkh Province"; + static readonly AfghanistanRegion1Code: string = "BAL"; + static readonly AfghanistanRegion2Name: string = "Bamyan Province"; + static readonly AfghanistanRegion2Code: string = "BAM"; + static readonly AfghanistanRegion3Name: string = "Badghis Province"; + static readonly AfghanistanRegion3Code: string = "BDG"; + + static readonly AfghanistanRegion1: string = "{\"name\":\"Balkh Province\",\"code\":\"BAL\"}"; + static readonly AfghanistanRegion2: string = "{\"name\":\"Bamyan Province\",\"code\":\"BAM\"}"; + static readonly AfghanistanRegion3: string = "{\"name\":\"Badghis Province\",\"code\":\"BDG\"}"; + + static readonly AfghanistanRegions: string = `[ + ${CountriesMocks.AfghanistanRegion1}, + ${CountriesMocks.AfghanistanRegion2}, + ${CountriesMocks.AfghanistanRegion3}, + {"name":"Badakhshan Province","code":"BDS"}, + {"name":"Baghlan Province","code":"BGL"}, + {"name":"Daykundi Province","code":"DAY"}, + {"name":"Farah Province","code":"FRA"}, + {"name":"Faryab Province","code":"FYB"}, + {"name":"Ghazni Province","code":"GHA"}, + {"name":"Ghōr Province","code":"GHO"}, + {"name":"Helmand Province","code":"HEL"}, + {"name":"Herat Province","code":"HER"}, + {"name":"Jowzjan Province","code":"JOW"}, + {"name":"Kabul Province","code":"KAB"}, + {"name":"Kandahar Province","code":"KAN"}, + {"name":"Kapisa Province","code":"KAP"}, + {"name":"Kunduz Province","code":"KDZ"}, + {"name":"Khost Province","code":"KHO"}, + {"name":"Kunar Province","code":"KNR"}, + {"name":"Laghman Province","code":"LAG"}, + {"name":"Logar Province","code":"LOG"}, + {"name":"Nangarhar Province","code":"NAN"}, + {"name":"Nimruz Province","code":"NIM"}, + {"name":"Nuristan Province","code":"NUR"}, + {"name":"Oruzgan","code":"ORU"}, + {"name":"Panjshir Province","code":"PAN"}, + {"name":"Parwan Province","code":"PAR"}, + {"name":"Paktia Province","code":"PIA"}, + {"name":"Paktika Province","code":"PKA"}, + {"name":"Samangan Province","code":"SAM"}, + {"name":"Sar-e Pol Province","code":"SAR"}, + {"name":"Takhar Province","code":"TAK"}, + {"name":"Urozgan Province","code":"URU"}, + {"name":"Maidan Wardak Province","code":"WAR"}, + {"name":"Zabul Province","code":"ZAB"} + ]`; + + static readonly AfghanistanName: string = "Afghanistan"; + static readonly AfghanistanCode: string = "AF"; + static readonly AfghanistanCountry: string = `{"name":"${CountriesMocks.AfghanistanName}","code":"${CountriesMocks.AfghanistanCode}","regions":${CountriesMocks.AfghanistanRegions}}`; + + static readonly CountriesJson: string = `[ + ${CountriesMocks.AfghanistanCountry}, + { + "name": "South Sudan", + "code": "SS", + "regions": [ + {"name":"Ruweng","code":""}, + {"name":"Maiwut","code":""}, + {"name":"Akobo","code":""}, + {"name":"Aweil","code":""}, + {"name":"Eastern Lakes","code":""}, + {"name":"Gogrial","code":""}, + {"name":"Lol","code":""}, + {"name":"Amadi State","code":""}, + {"name":"Yei River","code":""}, + {"name":"Fashoda","code":""}, + {"name":"Gok","code":""}, + {"name":"Tonj","code":""}, + {"name":"Twic","code":""}, + {"name":"Wau","code":""}, + {"name":"Gbudwe","code":""}, + {"name":"Imatong","code":""}, + {"name":"Jubek","code":""}, + {"name":"Maridi","code":""}, + {"name":"Terekeka","code":""}, + {"name":"Boma","code":""}, + {"name":"Bieh","code":""}, + {"name":"Central Upper Nile","code":""}, + {"name":"Latjoor","code":""}, + {"name":"Northern Liech","code":""}, + {"name":"Southern Liech","code":""}, + {"name":"Fangak","code":""}, + {"name":"Western Lakes","code":""}, + {"name":"Aweil East","code":""}, + {"name":"Northern Upper Nile","code":""}, + {"name":"Tambura","code":""}, + {"name":"Kapoeta","code":""}, + {"name":"Jonglei","code":"JG"} + ] + }, + { + "name": "Kosovo", + "code": "XK", + "regions": [] + } + ]`; +} diff --git a/packages/sdk/test/infrastructure/resources/valid/CredentialTypeSchemaMocks.ts b/packages/sdk/test/infrastructure/resources/valid/CredentialTypeSchemaMocks.ts new file mode 100644 index 0000000..c0c158c --- /dev/null +++ b/packages/sdk/test/infrastructure/resources/valid/CredentialTypeSchemaMocks.ts @@ -0,0 +1,73 @@ +import { CredentialTypesMocks } from "./CredentialTypesMocks"; +import { VCLCredentialTypes } from "../../../../src"; + +export class CredentialTypeSchemaMocks { + static readonly CredentialTypeSchemaJson: string = ` + { + "title": "vaccination-certificate", + "$id": "https://velocitynetwork.foundation/schemas/vaccination-certificate", + "type": "object", + "properties": { + "disease": { + "type": "string", + "description": "Disease or agent that the vaccination provides protection against" + }, + "vaccineDescription": { + "type": "string", + "description": "Generic description of the vaccine/prophylaxis" + }, + "vaccineType": { + "type": "string", + "description": "Generic description of the vaccine/prophylaxis or its component(s) [J07BX03 covid-19 vaccines]" + }, + "certifiedBy": { + "type": "string", + "description": "Entity that has issued the certificate (allowing to check the certificate)" + }, + "certificateNumber": { + "type": "string", + "description": "Unique identifier of the certificate (UVCI), to be printed (human readable) into the certificate; the unique identifier can be included in the IIS" + }, + "certificateValidFrom": { + "type": "string", + "format": "date-time", + "description": "Certificate valid from (required if known)" + }, + "certificateValidTo": { + "type": "string", + "format": "date-time", + "description": "Certificate valid until (validity can differ from the expected immunisation period)" + }, + "formVersion": { + "type": "string", + "pattern": "^1.0.0$", + "description": "Version of this minimum dataset definition" + } + }, + "required": [ + "disease", + "vaccineDescription", + "vaccineType", + "certifiedBy", + "certificateNumber", + "certificateValidFrom", + "formVersion" + ] + }`; + + static readonly CredentialType = { + payload: JSON.parse(CredentialTypesMocks.CredentialType2), + id: "5fe4a315d8b45dd2e80bd73a", + schema: "", + createdAt: "2022-03-17T09:24:38.448Z", + schemaName: "current-employment-position", + credentialType: "CurrentEmploymentPosition", + recommended: true, + jsonldContext: [], + issuerCategory: "RegularIssuer" + }; + + static readonly CredentialTypes = new VCLCredentialTypes( + [CredentialTypeSchemaMocks.CredentialType] + ); +} diff --git a/packages/sdk/test/infrastructure/resources/valid/CredentialTypesMocks.ts b/packages/sdk/test/infrastructure/resources/valid/CredentialTypesMocks.ts new file mode 100644 index 0000000..e70fde1 --- /dev/null +++ b/packages/sdk/test/infrastructure/resources/valid/CredentialTypesMocks.ts @@ -0,0 +1,33 @@ +export class CredentialTypesMocks { + static readonly CredentialType1: string = ` + { + "credentialType": "EducationDegree", + "schemaName": "education-degree", + "recommended": false, + "id": "5fe4a315d8b45dd2e80bd739", + "createdAt": "2022-03-17T09:24:38.448Z", + "updatedAt": "2022-03-17T09:24:38.448Z" + }`; + + static readonly CredentialType2: string = ` + { + "credentialType": "CurrentEmploymentPosition", + "schemaName": "current-employment-position", + "recommended": true, + "id": "5fe4a315d8b45dd2e80bd73a", + "createdAt": "2022-03-17T09:24:38.448Z", + "updatedAt": "2022-03-17T09:24:38.448Z" + }`; + + static readonly CredentialType3: string = ` + { + "credentialType": "PastEmploymentPosition", + "schemaName": "past-employment-position", + "recommended": false, + "id": "5fe4a315d8b45dd2e80bd73b", + "createdAt": "2022-03-17T09:24:38.448Z", + "updatedAt": "2022-03-17T09:24:38.448Z" + }`; + + static readonly CredentialTypesJsonStr: string = `[${CredentialTypesMocks.CredentialType1}, ${CredentialTypesMocks.CredentialType2}, ${CredentialTypesMocks.CredentialType3}]`; +} diff --git a/packages/sdk/test/infrastructure/resources/valid/DidJwkMocks.ts b/packages/sdk/test/infrastructure/resources/valid/DidJwkMocks.ts index bb9d73a..964ba25 100644 --- a/packages/sdk/test/infrastructure/resources/valid/DidJwkMocks.ts +++ b/packages/sdk/test/infrastructure/resources/valid/DidJwkMocks.ts @@ -1,4 +1,4 @@ -import { VCLDidJwk, VCLPublicJwk } from "../../../../src"; +import { VCLDidJwk } from "../../../../src"; class DidJwkMocks { static readonly DidJwkStr = `{ "did": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6InI5ZnlhNTJJbG1UbzN5YlMwd19HZWZlUV9SWDJFSF9ISm1TV3FZWU8ySlkiLCJ5IjoicFFUUmE3R2txYzVrajZvZGVNcXBnVjVUNExqYlphNEY1S1R1MkpEclduYyJ9", "kid": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6InI5ZnlhNTJJbG1UbzN5YlMwd19HZWZlUV9SWDJFSF9ISm1TV3FZWU8ySlkiLCJ5IjoicFFUUmE3R2txYzVrajZvZGVNcXBnVjVUNExqYlphNEY1S1R1MkpEclduYyJ9#0", "keyId": "6630f0a67b097c289711f583", "publicJwk": { "kty": "EC", "crv": "P-256", "y": "pQTRa7Gkqc5kj6odeMqpgV5T4LjbZa4F5KTu2JDrWnc", "x": "r9fya52IlmTo3ybS0w_GefeQ_RX2EH_HJmSWqYYO2JY" } }` diff --git a/packages/sdk/test/infrastructure/resources/valid/ExchangeProgressMocks.ts b/packages/sdk/test/infrastructure/resources/valid/ExchangeProgressMocks.ts new file mode 100644 index 0000000..e4f377c --- /dev/null +++ b/packages/sdk/test/infrastructure/resources/valid/ExchangeProgressMocks.ts @@ -0,0 +1,8 @@ +export class ExchangeProgressMocks { + static readonly ExchangeProgressJsonStr: string = `{ + "id": "64131231", + "type": "DISCLOSURE", + "disclosureComplete": true, + "exchangeComplete": true + }`; +} diff --git a/packages/sdk/test/infrastructure/resources/valid/IdentificationSubmissionMocks.ts b/packages/sdk/test/infrastructure/resources/valid/IdentificationSubmissionMocks.ts index 12c6ef5..3d6c979 100644 --- a/packages/sdk/test/infrastructure/resources/valid/IdentificationSubmissionMocks.ts +++ b/packages/sdk/test/infrastructure/resources/valid/IdentificationSubmissionMocks.ts @@ -8,7 +8,6 @@ import { VCLVerifiableCredential, VCLVerifiedProfile } from "../../../../src"; -import { DidJwkMocks } from "./DidJwkMocks"; export class IdentificationSubmissionMocks { static DidJwkJson = diff --git a/packages/sdk/test/infrastructure/resources/valid/OrganizationsMocks.ts b/packages/sdk/test/infrastructure/resources/valid/OrganizationsMocks.ts new file mode 100644 index 0000000..5d87c2f --- /dev/null +++ b/packages/sdk/test/infrastructure/resources/valid/OrganizationsMocks.ts @@ -0,0 +1,31 @@ +export class OrganizationsMocks { + static readonly OrganizationJsonStr: string = `{ + "id": "did:velocity:0x571cf9ef33b111b7060942eb43133c0b347c7ca3", + "name": "Universidad de Sant Cugat", + "logo": "https://docs.velocitycareerlabs.io/Logos/Universidad de Sant Cugat.png", + "location": { + "countryCode": "ES", + "regionCode": "CAT" + }, + "founded": "1984", + "website": "https://example.com", + "permittedVelocityServiceCategories": ["Issuer", null], + "service": [{ + "id": "did:velocity:0x571cf9ef33b111b7060942eb43133c0b347c7ca3#credential-agent-issuer-1", + "type": "VelocityCredentialAgentIssuer_v1.0", + "credentialTypes": ["Course", "EducationDegree", "Badge"], + "serviceEndpoint": "https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:velocity:0x571cf9ef33b111b7060942eb43133c0b347c7ca3/issue/get-credential-manifest" + }] + }`; + + static readonly OrganizationJsonResultStr: string = `{"result": [${OrganizationsMocks.OrganizationJsonStr}]}`; + + static readonly ServiceJsonStr: string = `{ + "id": "did:velocity:0x571cf9ef33b111b7060942eb43133c0b347c7ca3#credential-agent-issuer-1", + "type": "VelocityCredentialAgentIssuer_v1.0", + "credentialTypes": ["Course", "EducationDegree", "Badge"], + "serviceEndpoint": "https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:velocity:0x571cf9ef33b111b7060942eb43133c0b347c7ca3/issue/get-credential-manifest" + }`; + + static readonly ServiceEndpoint: string = "https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:velocity:0x571cf9ef33b111b7060942eb43133c0b347c7ca3/issue/get-credential-manifest"; +} diff --git a/packages/sdk/test/usecases/CountriesUseCase.test.ts b/packages/sdk/test/usecases/CountriesUseCase.test.ts new file mode 100644 index 0000000..a8076d6 --- /dev/null +++ b/packages/sdk/test/usecases/CountriesUseCase.test.ts @@ -0,0 +1,31 @@ +import NetworkServiceSuccess from "../NetworkServiceSuccess"; +import CountriesUseCaseImpl from "../../src/impl/data/usecases/CountriesModelUseCaseImpl"; +import CountriesRepositoryImpl from "../../src/impl/data/repositories/CountriesRepositoryImpl"; +import { CountriesMocks } from "../infrastructure/resources/valid/CountriesMocks"; +import { VCLCountries } from "../../src"; + +describe("CredentialManifestUseCase Tests", () => { + const subject = new CountriesUseCaseImpl( + new CountriesRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(CountriesMocks.CountriesJson)) + ) + ) + + test("testGetCountriesSuccess", async () => { + const countries = await subject.getCountries(); + + const afghanistanCountry = countries.countryByCode(VCLCountries.AF) + const afghanistanRegions = afghanistanCountry?.regions + + expect(afghanistanCountry?.code).toBe(CountriesMocks.AfghanistanCode) + expect(afghanistanCountry?.name).toBe(CountriesMocks.AfghanistanName) + + expect(afghanistanRegions?.all[0].name).toBe(CountriesMocks.AfghanistanRegion1Name) + expect(afghanistanRegions?.all[0].code).toBe(CountriesMocks.AfghanistanRegion1Code) + expect(afghanistanRegions?.all[1].name).toBe(CountriesMocks.AfghanistanRegion2Name) + expect(afghanistanRegions?.all[1].code).toBe(CountriesMocks.AfghanistanRegion2Code) + expect(afghanistanRegions?.all[2].name).toBe(CountriesMocks.AfghanistanRegion3Name) + expect(afghanistanRegions?.all[2].code).toBe(CountriesMocks.AfghanistanRegion3Code) + }) + +}); diff --git a/packages/sdk/test/usecases/CredentialManifestUseCase.test.ts b/packages/sdk/test/usecases/CredentialManifestUseCase.test.ts index 057635e..4f97322 100644 --- a/packages/sdk/test/usecases/CredentialManifestUseCase.test.ts +++ b/packages/sdk/test/usecases/CredentialManifestUseCase.test.ts @@ -37,7 +37,7 @@ describe("CredentialManifestUseCase Tests", () => { ); try { - const result = await subject1.getCredentialManifest( + const credentialManifest = await subject1.getCredentialManifest( new VCLCredentialManifestDescriptorByDeepLink( DeepLinkMocks.CredentialManifestDeepLinkDevNet, VCLIssuingType.Career, @@ -47,7 +47,6 @@ describe("CredentialManifestUseCase Tests", () => { ), new VCLVerifiedProfile(JSON.parse(VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1)) ); - const [error, credentialManifest] = result.handleResult(); expect(credentialManifest?.jwt.encodedJwt).toBe(CredentialManifestMocks.JwtCredentialManifest1); expect(credentialManifest?.jwt.header).toStrictEqual(JSON.parse(CredentialManifestMocks.Header)); expect(credentialManifest?.jwt.payload).toStrictEqual(JSON.parse(CredentialManifestMocks.Payload)); @@ -75,7 +74,7 @@ describe("CredentialManifestUseCase Tests", () => { ); try { - const result = await subject2.getCredentialManifest( + await subject2.getCredentialManifest( new VCLCredentialManifestDescriptorByDeepLink( DeepLinkMocks.CredentialManifestDeepLinkDevNet, VCLIssuingType.Career, @@ -84,13 +83,8 @@ describe("CredentialManifestUseCase Tests", () => { ), new VCLVerifiedProfile(JSON.parse(VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1)) ); - const [error, credentialManifest] = result.handleResult(); - + } catch (error: any) { expect(error?.errorCode).toBe(VCLErrorCode.SdkError); - - } catch (error) { - console.log(error); - expect(error).toBeNull(); } }); }); \ No newline at end of file diff --git a/packages/sdk/test/usecases/CredentialTypeSchemaUseCase.test.ts b/packages/sdk/test/usecases/CredentialTypeSchemaUseCase.test.ts new file mode 100644 index 0000000..d0d0373 --- /dev/null +++ b/packages/sdk/test/usecases/CredentialTypeSchemaUseCase.test.ts @@ -0,0 +1,23 @@ +import NetworkServiceSuccess from "../NetworkServiceSuccess"; +import CredentialTypeSchemasUseCaseImpl from "../../src/impl/data/usecases/CredentialTypeSchemasUseCaseImpl"; +import CredentialTypeSchemaRepositoryImpl from "../../src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl"; +import { CredentialTypeSchemaMocks } from "../infrastructure/resources/valid/CredentialTypeSchemaMocks"; +import { expect } from "@jest/globals"; + +describe("CredentialTypeSchemaUseCase Tests", () => { + const subject = new CredentialTypeSchemasUseCaseImpl( + new CredentialTypeSchemaRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(CredentialTypeSchemaMocks.CredentialTypeSchemaJson)), + ), + CredentialTypeSchemaMocks.CredentialTypes, + ) + + test("testGetCredentialTypeSchemas", async () => { + const credTypeSchemas = await subject.getCredentialTypeSchemas() + + expect( + credTypeSchemas.all[CredentialTypeSchemaMocks.CredentialType.schemaName]?.payload).toStrictEqual( + JSON.parse(CredentialTypeSchemaMocks.CredentialTypeSchemaJson) + ) + }) +}); \ No newline at end of file diff --git a/packages/sdk/test/usecases/CredentialTypesUIFormSchemaUseCase.test.ts b/packages/sdk/test/usecases/CredentialTypesUIFormSchemaUseCase.test.ts index 25fdbd5..490d9a8 100644 --- a/packages/sdk/test/usecases/CredentialTypesUIFormSchemaUseCase.test.ts +++ b/packages/sdk/test/usecases/CredentialTypesUIFormSchemaUseCase.test.ts @@ -43,10 +43,7 @@ describe("CredentialTypesUIFormSchemaUseCase Tests", () => { mockedCountries ); - const [err, result] = response.handleResult(); - // Assertions - // Assuming `result` is already defined as VCLResult or similar - const addressJsonObj = result?.payload["place"]; + const addressJsonObj = response?.payload["place"]; const addressCountryJsonObj = addressJsonObj[VCLCredentialTypesUIFormSchema.KeyAddressCountry]; const addressRegionJsonObj = @@ -102,9 +99,7 @@ describe("CredentialTypesUIFormSchemaUseCase Tests", () => { mockedCountries ); - const [err, result] = response.handleResult(); - - const addressJsonObj = result?.payload["place"]; + const addressJsonObj = response?.payload["place"]; const addressCountryJsonObj = addressJsonObj[VCLCredentialTypesUIFormSchema.KeyAddressCountry]; const addressRegionJsonObj = @@ -154,9 +149,7 @@ describe("CredentialTypesUIFormSchemaUseCase Tests", () => { mockedCountries ); - const [err, result] = response.handleResult(); - - const addressJsonObj = result?.payload["place"]; + const addressJsonObj = response?.payload["place"]; const addressCountryJsonObj = addressJsonObj[VCLCredentialTypesUIFormSchema.KeyAddressCountry]; const addressRegionJsonObj = @@ -206,9 +199,7 @@ describe("CredentialTypesUIFormSchemaUseCase Tests", () => { mockedCountries ); - const [err, result] = response.handleResult(); - - const addressJsonObj = result?.payload["place"]; + const addressJsonObj = response?.payload["place"]; const addressCountryJsonObj = addressJsonObj[VCLCredentialTypesUIFormSchema.KeyAddressCountry]; const addressRegionJsonObj = diff --git a/packages/sdk/test/usecases/CredentialTypesUseCase.test.ts b/packages/sdk/test/usecases/CredentialTypesUseCase.test.ts new file mode 100644 index 0000000..6f6e478 --- /dev/null +++ b/packages/sdk/test/usecases/CredentialTypesUseCase.test.ts @@ -0,0 +1,94 @@ +import { CredentialTypesMocks } from "../infrastructure/resources/valid/CredentialTypesMocks"; +import NetworkServiceSuccess from "../NetworkServiceSuccess"; +import CredentialTypesRepositoryImpl from "../../src/impl/data/repositories/CredentialTypesRepositoryImpl"; +import CredentialTypesUseCaseImpl from "../../src/impl/data/usecases/CredentialTypesUseCaseImpl"; +import { VCLCredentialType, VCLErrorCode } from "../../src"; +import { expect } from "@jest/globals"; + +describe("CredentialTypesUseCaseImpl Tests", () => { + const subject1 = new CredentialTypesUseCaseImpl( + new CredentialTypesRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(CredentialTypesMocks.CredentialTypesJsonStr)), + )) + const subject2 = new CredentialTypesUseCaseImpl( + new CredentialTypesRepositoryImpl( + new NetworkServiceSuccess({wrong: 'payload'}), + )) + + test("testGetCountriesSuccess", async () => { + const credentialTypes = await subject1.getCredentialTypes(); + + compareCredentialTypes(credentialTypes.all!, getExpectedCredentialTypesArr()) + compareCredentialTypes(credentialTypes.recommendedTypes!, getExpectedRecommendedCredentialTypesArr()) + }) + + test("testGetCountriesFailure", async () => { + try { + await subject2.getCredentialTypes(); + expect(false).toBe(true); + } catch (error: any) { + expect(error.errorCode).toBe(VCLErrorCode.SdkError.toString()); + } + }) + + const compareCredentialTypes = ( + credentialTypesArr1: VCLCredentialType[], + credentialTypesArr2: VCLCredentialType[] + ) => { + for (let i = 0; i < credentialTypesArr1.length; i++) { + expect(credentialTypesArr1[i].payload).toStrictEqual(credentialTypesArr2[i].payload); + expect(credentialTypesArr1[i].id).toBe(credentialTypesArr2[i].id); + expect(credentialTypesArr1[i].schema).toBe(credentialTypesArr2[i].schema); + expect(credentialTypesArr1[i].createdAt).toBe(credentialTypesArr2[i].createdAt); + expect(credentialTypesArr1[i].schemaName).toBe(credentialTypesArr2[i].schemaName); + expect(credentialTypesArr1[i].credentialType).toBe(credentialTypesArr2[i].credentialType); + expect(credentialTypesArr1[i].recommended).toBe(credentialTypesArr2[i].recommended); + } + } + + const getExpectedCredentialTypesArr = (): VCLCredentialType[] => { + return [ + { + payload: JSON.parse(CredentialTypesMocks.CredentialType1), + id: "5fe4a315d8b45dd2e80bd739", + schema: null, + createdAt: "2022-03-17T09:24:38.448Z", + schemaName: "education-degree", + credentialType: "EducationDegree", + recommended: false + }, + { + payload: JSON.parse(CredentialTypesMocks.CredentialType2), + id: "5fe4a315d8b45dd2e80bd73a", + schema: null, + createdAt: "2022-03-17T09:24:38.448Z", + schemaName: "current-employment-position", + credentialType: "CurrentEmploymentPosition", + recommended: true + }, + { + payload: JSON.parse(CredentialTypesMocks.CredentialType3), + id: "5fe4a315d8b45dd2e80bd73b", + schema: null, + createdAt: "2022-03-17T09:24:38.448Z", + schemaName: "past-employment-position", + credentialType: "PastEmploymentPosition", + recommended: false + } + ]; + } + + const getExpectedRecommendedCredentialTypesArr = (): VCLCredentialType[] => { + return [ + { + payload: JSON.parse(CredentialTypesMocks.CredentialType2), + id: "5fe4a315d8b45dd2e80bd73a", + schema: null, + createdAt: "2022-03-17T09:24:38.448Z", + schemaName: "current-employment-position", + credentialType: "CurrentEmploymentPosition", + recommended: true + } + ]; + } +}); \ No newline at end of file diff --git a/packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts b/packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts new file mode 100644 index 0000000..0ebda4e --- /dev/null +++ b/packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts @@ -0,0 +1,49 @@ +import NetworkServiceSuccess from "../NetworkServiceSuccess"; +import ExchangeProgressRepositoryImpl from "../../src/impl/data/repositories/ExchangeProgressRepositoryImpl"; +import ExchangeProgressUseCaseImpl from "../../src/impl/data/usecases/ExchangeProgressUseCaseImpl"; +import { ExchangeProgressMocks } from "../infrastructure/resources/valid/ExchangeProgressMocks"; +import { Dictionary, VCLErrorCode, VCLExchange, VCLExchangeDescriptor, VCLToken } from "../../src"; +import { mock } from "node:test"; +import { beforeAll, expect } from "@jest/globals"; + +describe("ExchangeProgressUseCase Tests", () => { + const subject1 = new ExchangeProgressUseCaseImpl( + new ExchangeProgressRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(ExchangeProgressMocks.ExchangeProgressJsonStr)) + ) + ) + const subject2 = new ExchangeProgressUseCaseImpl( + new ExchangeProgressRepositoryImpl( + new NetworkServiceSuccess({ wrong: 'payload' }) + ) + ) + const exchangeDescriptor = { + exchangeId: "", + processUri: "", + sessionToken: new VCLToken("") + } as VCLExchangeDescriptor; + + test("testGetExchangeProgressSuccess", async () => { + const exchange = await subject1.getExchangeProgress(exchangeDescriptor) + + expect(exchange).toStrictEqual(expectedExchange(JSON.parse(ExchangeProgressMocks.ExchangeProgressJsonStr))) + }); + + test("testGetExchangeProgressFailure", async () => { + try { + await subject1.getExchangeProgress(exchangeDescriptor) + } catch (error: any) { + expect(error.errorCode).toBe(VCLErrorCode.SdkError.toString()) + } + }); + + const expectedExchange = (exchangeJsonObj: Dictionary): VCLExchange => { + return new VCLExchange( + exchangeJsonObj[VCLExchange.KeyId], + exchangeJsonObj[VCLExchange.KeyType], + exchangeJsonObj[VCLExchange.KeyDisclosureComplete], + exchangeJsonObj[VCLExchange.KeyExchangeComplete] + ); + } + +}); \ No newline at end of file diff --git a/packages/sdk/test/usecases/GenerateOffersUseCase.test.ts b/packages/sdk/test/usecases/GenerateOffersUseCase.test.ts index af5e748..c15c527 100644 --- a/packages/sdk/test/usecases/GenerateOffersUseCase.test.ts +++ b/packages/sdk/test/usecases/GenerateOffersUseCase.test.ts @@ -3,7 +3,7 @@ import GenerateOffersRepositoryImpl from "../../src/impl/data/repositories/Gener import GenerateOffersUseCaseImpl from "../../src/impl/data/usecases/GenerateOffersUseCaseImpl"; import NetworkServiceSuccess from "../NetworkServiceSuccess"; import { GenerateOffersMocks } from "../infrastructure/resources/valid/GenerateOffersMocks"; -import { VCLCredentialManifest, VCLGenerateOffersDescriptor, VCLToken, VCLVerifiedProfile } from "../../src"; +import { VCLCredentialManifest, VCLGenerateOffersDescriptor, VCLVerifiedProfile } from "../../src"; import { VerifiedProfileMocks } from "../infrastructure/resources/valid/VerifiedProfileMocks"; import { DidJwkMocks } from "../infrastructure/resources/valid/DidJwkMocks"; import { CommonMocks } from "../infrastructure/resources/CommonMocks"; @@ -38,8 +38,7 @@ describe("GenerateOffersUseCase Tests", () => { [] ) - const result = await subject1.generateOffers(CommonMocks.Token, generateOffersDescriptor); - const [error, generatedOffers] = result.handleResult(); + const generatedOffers = await subject1.generateOffers(generateOffersDescriptor, CommonMocks.Token); expect(generatedOffers?.payload).toStrictEqual(GenerateOffersMocks.GeneratedOffersJsonObj); expect(generatedOffers?.all[0]).toStrictEqual(expectedOffer1); @@ -68,8 +67,7 @@ describe("GenerateOffersUseCase Tests", () => { [] ) - const result = await subject1.generateOffers(CommonMocks.Token, generateOffersDescriptor); - const [error, generatedOffers] = result.handleResult(); + const generatedOffers = await subject1.generateOffers(generateOffersDescriptor, CommonMocks.Token); expect(generatedOffers?.payload).toStrictEqual(GenerateOffersMocks.GeneratedOffersJsonArr); expect(generatedOffers?.all[0]).toStrictEqual(expectedOffer1); @@ -98,8 +96,7 @@ describe("GenerateOffersUseCase Tests", () => { [] ) - const result = await subject2.generateOffers(CommonMocks.Token, generateOffersDescriptor); - const [error, generatedOffers] = result.handleResult(); + const generatedOffers = await subject2.generateOffers(generateOffersDescriptor, CommonMocks.Token); expect(generatedOffers?.payload).toStrictEqual({}); expect(generatedOffers?.all).toStrictEqual([]); @@ -127,8 +124,7 @@ describe("GenerateOffersUseCase Tests", () => { [] ) - const result = await subject3.generateOffers(CommonMocks.Token, generateOffersDescriptor); - const [error, generatedOffers] = result.handleResult(); + const generatedOffers = await subject3.generateOffers(generateOffersDescriptor, CommonMocks.Token); expect(generatedOffers?.payload).toStrictEqual([]); expect(generatedOffers?.all).toStrictEqual([]); diff --git a/packages/sdk/test/usecases/IdentificationSubmissionUseCase.test.ts b/packages/sdk/test/usecases/IdentificationSubmissionUseCase.test.ts index cbb5ef8..2c83011 100644 --- a/packages/sdk/test/usecases/IdentificationSubmissionUseCase.test.ts +++ b/packages/sdk/test/usecases/IdentificationSubmissionUseCase.test.ts @@ -1,39 +1,25 @@ -import PresentationRequestUseCaseImpl from "../../src/impl/data/usecases/PresentationRequestUseCaseImpl"; -import PresentationRequestRepositoryImpl from "../../src/impl/data/repositories/PresentationRequestRepositoryImpl"; import NetworkServiceSuccess from "../NetworkServiceSuccess"; -import { PresentationRequestMocks } from "../infrastructure/resources/valid/PresentationRequestMocks"; -import ResolveKidRepositoryImpl from "../../src/impl/data/repositories/ResolveKidRepositoryImpl"; import JwtServiceRepositoryImpl from "../../src/impl/data/repositories/JwtServiceRepositoryImpl"; import { JwtSignServiceMock } from "../infrastructure/resources/jwt/JwtSignServiceMock"; import { JwtVerifyServiceMock } from "../infrastructure/resources/jwt/JwtVerifyServiceMock"; import { Dictionary, - VCLDeepLink, - VCLErrorCode, VCLExchange, VCLPresentationRequest, - VCLPresentationRequestDescriptor, VCLPresentationSubmission, - VCLPushDelegate, VCLSubmissionResult, - VCLToken, - VCLVerifiedProfile + VCLExchange, VCLJwt, + VCLSubmissionResult, + VCLToken } from "../../src"; -import { DeepLinkMocks } from "../infrastructure/resources/valid/DeepLinkMocks"; -import { DidJwkMocks } from "../infrastructure/resources/valid/DidJwkMocks"; -import PresentationSubmissionUseCase from "../../src/impl/domain/usecases/PresentationSubmissionUseCase"; -import { beforeAll, expect } from "@jest/globals"; -import PresentationSubmissionUseCaseImpl from "../../src/impl/data/usecases/PresentationSubmissionUseCaseImpl"; +import { expect } from "@jest/globals"; import { PresentationSubmissionMocks } from "../infrastructure/resources/valid/PresentationSubmissionMocks"; import SubmissionRepositoryImpl from "../../src/impl/data/repositories/SubmissionRepositoryImpl"; -import { CommonMocks } from "../infrastructure/resources/CommonMocks"; import IdentificationSubmissionUseCaseImpl from "../../src/impl/data/usecases/IdentificationSubmissionUseCaseImpl"; import VCLIdentificationSubmission from "../../src/api/entities/VCLIdentificationSubmission"; import { IdentificationSubmissionMocks } from "../infrastructure/resources/valid/IdentificationSubmissionMocks"; -import VCLResult from "../../src/api/entities/VCLResult"; -import VCLJwt from "../../src/api/entities/VCLJwt"; import VCLJwtDescriptor from "../../src/api/entities/VCLJwtDescriptor"; describe("PresentationSubmission Tests", () => { const jwtSignServiceMock = new JwtSignServiceMock(); jwtSignServiceMock.sign = jest.fn().mockResolvedValue( - Promise.resolve(new VCLResult.Success(VCLJwt.fromEncodedJwt(PresentationSubmissionMocks.JwtEncodedSubmission))) + Promise.resolve(VCLJwt.fromEncodedJwt(PresentationSubmissionMocks.JwtEncodedSubmission)) ); const jwtVerifyServiceMock = new JwtVerifyServiceMock(); const jwtServiceRepository = new JwtServiceRepositoryImpl( @@ -78,8 +64,7 @@ describe("PresentationSubmission Tests", () => { PresentationSubmissionMocks.PresentationSubmissionResultJson, identificationSubmission.jti, identificationSubmission.submissionId - ) - const identificationSubmissionPayload = identificationSubmission.generatePayload() + ); test("testIdentificationSubmissionDidJwk", async () => { expect(IdentificationSubmissionMocks.CredentialManifest.didJwk).toStrictEqual(IdentificationSubmissionMocks.DidJwk) @@ -87,16 +72,14 @@ describe("PresentationSubmission Tests", () => { }); test("testIdentificationSubmissionSuccess", async () => { - const result = await subject.submit(identificationSubmission) - const [error, identificationSubmissionResult] = result.handleResult() + const identificationSubmissionResult = await subject.submit(identificationSubmission) expect(jwtSignServiceMock.sign).toHaveBeenCalledTimes(1) expect(jwtSignServiceMock.sign).toHaveBeenCalledWith( new VCLJwtDescriptor( - identificationSubmissionPayload, - identificationSubmission.iss, + identificationSubmission.generatePayload(identificationSubmission.didJwk.did), identificationSubmission.jti, - identificationSubmission.didJwk?.keyId + identificationSubmission.didJwk.did, ), identificationSubmission.didJwk, null, @@ -107,6 +90,5 @@ describe("PresentationSubmission Tests", () => { expect(identificationSubmissionResult?.exchange.id).toBe(expectedPresentationSubmissionResult.exchange.id) expect(identificationSubmissionResult?.jti).toBe(expectedPresentationSubmissionResult.jti) expect(identificationSubmissionResult?.submissionId).toBe(expectedPresentationSubmissionResult.submissionId) - expect(error).toBeNull() }); }); \ No newline at end of file diff --git a/packages/sdk/test/usecases/OrganizationsUseCase.test.ts b/packages/sdk/test/usecases/OrganizationsUseCase.test.ts new file mode 100644 index 0000000..f84793b --- /dev/null +++ b/packages/sdk/test/usecases/OrganizationsUseCase.test.ts @@ -0,0 +1,31 @@ +import NetworkServiceSuccess from "../NetworkServiceSuccess"; +import { VCLOrganizationsSearchDescriptor, VCLService } from "../../src"; +import OrganizationsUseCaseImpl from "../../src/impl/data/usecases/OrganizationsUseCaseImpl"; +import OrganizationsRepositoryImpl from "../../src/impl/data/repositories/OrganizationsRepositoryImpl"; +import { OrganizationsMocks } from "../infrastructure/resources/valid/OrganizationsMocks"; + +describe("OrganizationsUseCase Tests", () => { + const subject = new OrganizationsUseCaseImpl( + new OrganizationsRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(OrganizationsMocks.OrganizationJsonResultStr)), + ) + ) + + test("testSearchForOrganizationsSuccess", async () => { + const serviceJsonMock = JSON.parse(OrganizationsMocks.ServiceJsonStr) + + const orgs = await subject.searchForOrganizations( + new VCLOrganizationsSearchDescriptor(null, null, null, "") + ) + const serviceCredentialAgentIssuer = orgs.all[0].serviceCredentialAgentIssuers[0] + expect(serviceCredentialAgentIssuer.payload).toStrictEqual(serviceJsonMock) + expect(serviceCredentialAgentIssuer.id).toBe(serviceJsonMock[VCLService.KeyId]) + expect(serviceCredentialAgentIssuer.type).toBe(serviceJsonMock[VCLService.KeyType]) + expect( + serviceCredentialAgentIssuer.credentialTypes).toStrictEqual(serviceJsonMock[VCLService.KeyCredentialTypes] + ) + expect(serviceCredentialAgentIssuer.serviceEndpoint).toBe(OrganizationsMocks.ServiceEndpoint) + }) + +}); + diff --git a/packages/sdk/test/usecases/PresentationRequestUseCase.test.ts b/packages/sdk/test/usecases/PresentationRequestUseCase.test.ts index b3b03b1..7040038 100644 --- a/packages/sdk/test/usecases/PresentationRequestUseCase.test.ts +++ b/packages/sdk/test/usecases/PresentationRequestUseCase.test.ts @@ -37,7 +37,7 @@ describe("PresentationRequestUseCase Tests", () => { ) ) - const result = await subject1.getPresentationRequest( + const presentationRequest = await subject1.getPresentationRequest( new VCLPresentationRequestDescriptor( DeepLinkMocks.PresentationRequestDeepLinkDevNet, new VCLPushDelegate( @@ -49,13 +49,11 @@ describe("PresentationRequestUseCase Tests", () => { ), new VCLVerifiedProfile({}) ); - const [error, presentationRequest] = result.handleResult(); - - expect(presentationRequest?.jwt).toStrictEqual(PresentationRequestMocks.PresentationRequestJwt); - expect(presentationRequest?.pushDelegate?.pushUrl).toBe(pushUrl); - expect(presentationRequest?.pushDelegate?.pushToken).toBe(pushToken); - expect(presentationRequest?.didJwk).toStrictEqual(DidJwkMocks.DidJwk); - expect(presentationRequest?.remoteCryptoServicesToken?.value).toBe('some token'); + expect(presentationRequest.jwt).toStrictEqual(PresentationRequestMocks.PresentationRequestJwt); + expect(presentationRequest.pushDelegate?.pushUrl).toBe(pushUrl); + expect(presentationRequest.pushDelegate?.pushToken).toBe(pushToken); + expect(presentationRequest.didJwk).toStrictEqual(DidJwkMocks.DidJwk); + expect(presentationRequest.remoteCryptoServicesToken?.value).toBe('some token'); }); @@ -74,22 +72,22 @@ describe("PresentationRequestUseCase Tests", () => { new JwtVerifyServiceMock() ) ) - - const result = await subject2.getPresentationRequest( - new VCLPresentationRequestDescriptor( - DeepLinkMocks.PresentationRequestDeepLinkDevNet, - new VCLPushDelegate( - pushUrl, - pushToken + try { + // eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars + const presentationRequest = await subject2.getPresentationRequest( + new VCLPresentationRequestDescriptor( + DeepLinkMocks.PresentationRequestDeepLinkDevNet, + new VCLPushDelegate( + pushUrl, + pushToken + ), + DidJwkMocks.DidJwk, + new VCLToken("some token") ), - DidJwkMocks.DidJwk, - new VCLToken("some token") - ), - new VCLVerifiedProfile({}) - ); - const [error, presentationRequest] = result.handleResult(); - - expect(error?.errorCode).toBe(VCLErrorCode.SdkError); - expect(presentationRequest).toBeNull(); + new VCLVerifiedProfile({}) + ); + } catch (error: any) { + expect(error.errorCode).toBe(VCLErrorCode.SdkError); + } }); }); \ No newline at end of file diff --git a/packages/sdk/test/usecases/PresentationSubmissionUseCase.test.ts b/packages/sdk/test/usecases/PresentationSubmissionUseCase.test.ts index 5ff70a7..9bf4c68 100644 --- a/packages/sdk/test/usecases/PresentationSubmissionUseCase.test.ts +++ b/packages/sdk/test/usecases/PresentationSubmissionUseCase.test.ts @@ -1,24 +1,18 @@ -import PresentationRequestUseCaseImpl from "../../src/impl/data/usecases/PresentationRequestUseCaseImpl"; -import PresentationRequestRepositoryImpl from "../../src/impl/data/repositories/PresentationRequestRepositoryImpl"; import NetworkServiceSuccess from "../NetworkServiceSuccess"; -import { PresentationRequestMocks } from "../infrastructure/resources/valid/PresentationRequestMocks"; -import ResolveKidRepositoryImpl from "../../src/impl/data/repositories/ResolveKidRepositoryImpl"; import JwtServiceRepositoryImpl from "../../src/impl/data/repositories/JwtServiceRepositoryImpl"; import { JwtSignServiceMock } from "../infrastructure/resources/jwt/JwtSignServiceMock"; import { JwtVerifyServiceMock } from "../infrastructure/resources/jwt/JwtVerifyServiceMock"; import { Dictionary, VCLDeepLink, - VCLErrorCode, VCLExchange, VCLPresentationRequest, - VCLPresentationRequestDescriptor, VCLPresentationSubmission, - VCLPushDelegate, VCLSubmissionResult, + VCLExchange, VCLPresentationRequest, + VCLPresentationSubmission, + VCLSubmissionResult, VCLToken, VCLVerifiedProfile } from "../../src"; -import { DeepLinkMocks } from "../infrastructure/resources/valid/DeepLinkMocks"; import { DidJwkMocks } from "../infrastructure/resources/valid/DidJwkMocks"; -import PresentationSubmissionUseCase from "../../src/impl/domain/usecases/PresentationSubmissionUseCase"; -import { beforeAll, expect } from "@jest/globals"; +import { expect } from "@jest/globals"; import PresentationSubmissionUseCaseImpl from "../../src/impl/data/usecases/PresentationSubmissionUseCaseImpl"; import { PresentationSubmissionMocks } from "../infrastructure/resources/valid/PresentationSubmissionMocks"; import SubmissionRepositoryImpl from "../../src/impl/data/repositories/SubmissionRepositoryImpl"; @@ -74,13 +68,11 @@ describe("PresentationSubmission Tests", () => { presentationSubmission.submissionId ) test("testGetPresentationSubmissionSuccess", async () => { - const result = await subject.submit(presentationSubmission) - const [error, presentationSubmissionResult] = result.handleResult() + const presentationSubmissionResult = await subject.submit(presentationSubmission) expect(presentationSubmissionResult?.sessionToken.value).toBe(expectedPresentationSubmissionResult.sessionToken.value) expect(presentationSubmissionResult?.exchange.id).toBe(expectedPresentationSubmissionResult.exchange.id) expect(presentationSubmissionResult?.jti).toBe(expectedPresentationSubmissionResult.jti) expect(presentationSubmissionResult?.submissionId).toBe(expectedPresentationSubmissionResult.submissionId) - expect(error).toBeNull() }); }); \ No newline at end of file diff --git a/packages/sdk/test/usecases/VerifiedProfileUseCase.test.ts b/packages/sdk/test/usecases/VerifiedProfileUseCase.test.ts new file mode 100644 index 0000000..fd405c4 --- /dev/null +++ b/packages/sdk/test/usecases/VerifiedProfileUseCase.test.ts @@ -0,0 +1,47 @@ +import NetworkServiceSuccess from "../NetworkServiceSuccess"; +import VerifiedProfileUseCaseImpl from "../../src/impl/data/usecases/VerifiedProfileUseCaseImpl"; +import VerifiedProfileRepositoryImpl from "../../src/impl/data/repositories/VerifiedProfileRepositoryImpl"; +import { VerifiedProfileMocks } from "../infrastructure/resources/valid/VerifiedProfileMocks"; +import { VCLVerifiedProfile, VCLVerifiedProfileDescriptor } from "../../src"; +import { expect } from "@jest/globals"; + +describe("CredentialTypesUseCaseImpl Tests", () => { + const subject1 = new VerifiedProfileUseCaseImpl(new VerifiedProfileRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1)) + )) + const subject2 = new VerifiedProfileUseCaseImpl(new VerifiedProfileRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(VerifiedProfileMocks.VerifiedProfileIssuerInspectorJsonStr)) + )) + const subject3 = new VerifiedProfileUseCaseImpl(new VerifiedProfileRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(VerifiedProfileMocks.VerifiedProfileNotaryIssuerJsonStr)) + )) + const subject4 = new VerifiedProfileUseCaseImpl(new VerifiedProfileRepositoryImpl( + new NetworkServiceSuccess(JSON.parse(VerifiedProfileMocks.VerifiedProfileNotaryIssuerJsonStr)) + )) + + test("testGetVerifiedProfileIssuerSuccess", async () => { + const verifiedProfile = await subject1.getVerifiedProfile(new VCLVerifiedProfileDescriptor("did123")) + compareVerifiedProfile(verifiedProfile) + }) + + test("testGetVerifiedProfileIssuerInspector1Success", async () => { + const verifiedProfile = await subject2.getVerifiedProfile(new VCLVerifiedProfileDescriptor("did123")) + compareVerifiedProfile(verifiedProfile) + }) + + test("testGetVerifiedProfileIssuerInspector2Success", async () => { + const verifiedProfile = await subject3.getVerifiedProfile(new VCLVerifiedProfileDescriptor("did123")) + compareVerifiedProfile(verifiedProfile) + }) + + test("testGetVerifiedProfileIssuerNotaryIssuer2Success", async () => { + const verifiedProfile = await subject4.getVerifiedProfile(new VCLVerifiedProfileDescriptor("did123")) + compareVerifiedProfile(verifiedProfile) + }) + + const compareVerifiedProfile = (verifiedProfile: VCLVerifiedProfile) => { + expect(verifiedProfile.id).toBe(VerifiedProfileMocks.ExpectedId) + expect(verifiedProfile.logo).toBe(VerifiedProfileMocks.ExpectedLogo) + expect(verifiedProfile.name).toBe(VerifiedProfileMocks.ExpectedName) + } +}); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 8da7193..9a0109a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2987,10 +2987,10 @@ eslint-ast-utils@~1.1.0: lodash.get "^4.4.2" lodash.zip "^4.2.0" -eslint-config-prettier@~8.8.0: - version "8.8.0" - resolved "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.8.0.tgz#bfda738d412adc917fd7b038857110efe98c9348" - integrity sha512-wLbQiFre3tdGgpDv67NQKnJuTlcUVYHas3k+DZCc2U2BadthoEY4B7hLPvAxaqdyOGCzuLfii2fqGph10va7oA== +eslint-config-prettier@~9.1.0: + version "9.1.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f" + integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== eslint-import-resolver-node@^0.3.9: version "0.3.9" @@ -3065,10 +3065,10 @@ eslint-plugin-prettier@~4.2.1: dependencies: prettier-linter-helpers "^1.0.0" -eslint-plugin-unused-imports@^3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.2.0.tgz#63a98c9ad5f622cd9f830f70bc77739f25ccfe0d" - integrity sha512-6uXyn6xdINEpxE1MtDjxQsyXB37lfyO2yKGVVgtD7WEWQGORSOZjgrD6hBhvGv4/SO+TOlS+UnC6JppRqbuwGQ== +eslint-plugin-unused-imports@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.0.0.tgz#93f3a7ee6088221e4a1d7127866e05d5917a9f65" + integrity sha512-mzM+y2B7XYpQryVa1usT+Y/BdNAtAZiXzwpSyDCboFoJN/LZRN67TNvQxKtuTK/Aplya3sLNQforiubzPPaIcQ== dependencies: eslint-rule-composer "^0.3.0" @@ -6396,11 +6396,6 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@~2.8.7: - version "2.8.8" - resolved "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da" - integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q== - pretty-format@29.4.3: version "29.4.3" resolved "https://registry.npmjs.org/pretty-format/-/pretty-format-29.4.3.tgz#25500ada21a53c9e8423205cf0337056b201244c" From e910015dffa44b2653c8759deae315e8be5d4bce Mon Sep 17 00:00:00 2001 From: Michael Avoyan Date: Wed, 29 May 2024 13:34:19 +0300 Subject: [PATCH 2/2] fixes --- .../CredentialTypeSchemaRepositoryImpl.ts | 1 - .../data/usecases/CountriesModelUseCaseImpl.ts | 3 ++- .../CredentialTypesUIFormSchemaUseCaseImpl.ts | 3 ++- .../usecases/ExchangeProgressUseCaseImpl.ts | 3 ++- .../data/usecases/FinalizeOffersUseCaseImpl.ts | 3 ++- .../data/usecases/GenerateOffersUseCaseImpl.ts | 3 ++- .../data/usecases/JwtServiceUseCaseImpl.ts | 3 ++- .../data/usecases/KeyServiceUseCaseImpl.ts | 3 ++- .../data/usecases/OrganizationsUseCaseImpl.ts | 3 ++- .../usecases/PresentationRequestUseCaseImpl.ts | 2 +- .../data/usecases/SubmissionUseCaseImpl.ts | 3 ++- .../usecases/VerifiedProfileUseCaseImpl.ts | 3 ++- .../usecases/CredentialManifestUseCase.test.ts | 3 ++- .../usecases/ExchangeProgressUseCase.test.ts | 18 +++++++++--------- .../PresentationRequestUseCase.test.ts | 3 ++- 15 files changed, 34 insertions(+), 23 deletions(-) diff --git a/packages/sdk/src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl.ts b/packages/sdk/src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl.ts index ce4def1..99e3ed8 100644 --- a/packages/sdk/src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl.ts +++ b/packages/sdk/src/impl/data/repositories/CredentialTypeSchemaRepositoryImpl.ts @@ -3,7 +3,6 @@ import NetworkService from "../../domain/infrastructure/network/NetworkService"; import CredentialTypeSchemaRepository from "../../domain/repositories/CredentialTypeSchemaRepository"; import { HttpMethod } from "../infrastructure/network/Request"; import Urls, { HeaderKeys, HeaderValues } from "./Urls"; -import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes"; export default class CredentialTypeSchemaRepositoryImpl implements CredentialTypeSchemaRepository diff --git a/packages/sdk/src/impl/data/usecases/CountriesModelUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/CountriesModelUseCaseImpl.ts index 1c971e1..cb44c4c 100644 --- a/packages/sdk/src/impl/data/usecases/CountriesModelUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/CountriesModelUseCaseImpl.ts @@ -1,6 +1,7 @@ import VCLCountries from "../../../api/entities/VCLCountries"; import CountriesRepository from "../../domain/repositories/CountriesRepository"; import CountriesUseCase from "../../domain/usecases/CountriesModelUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class CountriesUseCaseImpl implements CountriesUseCase { constructor(private readonly countriesRepository: CountriesRepository) {} @@ -9,7 +10,7 @@ export default class CountriesUseCaseImpl implements CountriesUseCase { try { return await this.countriesRepository.getCountries(); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } } diff --git a/packages/sdk/src/impl/data/usecases/CredentialTypesUIFormSchemaUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/CredentialTypesUIFormSchemaUseCaseImpl.ts index 6a524a9..db9f950 100644 --- a/packages/sdk/src/impl/data/usecases/CredentialTypesUIFormSchemaUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/CredentialTypesUIFormSchemaUseCaseImpl.ts @@ -3,6 +3,7 @@ import VCLCredentialTypesUIFormSchema from "../../../api/entities/VCLCredentialT import VCLCredentialTypesUIFormSchemaDescriptor from "../../../api/entities/VCLCredentialTypesUIFormSchemaDescriptor"; import CredentialTypesUIFormSchemaRepository from "../../domain/repositories/CredentialTypesUIFormSchemaRepository"; import CredentialTypesUIFormSchemaUseCase from "../../domain/usecases/CredentialTypesUIFormSchemaUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class CredentialTypesUIFormSchemaUseCaseImpl implements CredentialTypesUIFormSchemaUseCase @@ -21,7 +22,7 @@ export default class CredentialTypesUIFormSchemaUseCaseImpl countries ); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } } diff --git a/packages/sdk/src/impl/data/usecases/ExchangeProgressUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/ExchangeProgressUseCaseImpl.ts index 9141191..3cba697 100644 --- a/packages/sdk/src/impl/data/usecases/ExchangeProgressUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/ExchangeProgressUseCaseImpl.ts @@ -2,6 +2,7 @@ import VCLExchange from "../../../api/entities/VCLExchange"; import VCLExchangeDescriptor from "../../../api/entities/VCLExchangeDescriptor"; import ExchangeProgressRepository from "../../domain/repositories/ExchangeProgressRepository"; import ExchangeProgressUseCase from "../../domain/usecases/ExchangeProgressUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class ExchangeProgressUseCaseImpl implements ExchangeProgressUseCase { constructor(private exchangeProgressRepository: ExchangeProgressRepository) { @@ -13,7 +14,7 @@ export default class ExchangeProgressUseCaseImpl implements ExchangeProgressUseC try { return await this.exchangeProgressRepository.getExchangeProgress(exchangeDescriptor); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } } diff --git a/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts index d8d2e32..c5f7345 100644 --- a/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/FinalizeOffersUseCaseImpl.ts @@ -5,6 +5,7 @@ import VCLToken from "../../../api/entities/VCLToken"; import FinalizeOffersRepository from "../../domain/repositories/FinalizeOffersRepository"; import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository"; import FinalizeOffersUseCase from "../../domain/usecases/FinalizeOffersUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class FinalizeOffersUseCaseImpl implements FinalizeOffersUseCase { @@ -38,7 +39,7 @@ export default class FinalizeOffersUseCaseImpl } return new VCLJwtVerifiableCredentials(passedCredentials, failedCredentials); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } diff --git a/packages/sdk/src/impl/data/usecases/GenerateOffersUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/GenerateOffersUseCaseImpl.ts index e8bba72..5687dda 100644 --- a/packages/sdk/src/impl/data/usecases/GenerateOffersUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/GenerateOffersUseCaseImpl.ts @@ -3,6 +3,7 @@ import VCLOffers from "../../../api/entities/VCLOffers"; import VCLToken from "../../../api/entities/VCLToken"; import GenerateOffersRepository from "../../domain/repositories/GenerateOffersRepository"; import GenerateOffersUseCase from "../../domain/usecases/GenerateOffersUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class GenerateOffersUseCaseImpl implements GenerateOffersUseCase @@ -16,7 +17,7 @@ export default class GenerateOffersUseCaseImpl try { return await this.generateOffersRepository.generateOffers(generateOffersDescriptor, sessionToken); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } } diff --git a/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts index eb72609..53d9ed2 100644 --- a/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts @@ -6,6 +6,7 @@ import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository import JwtServiceUseCase from "../../domain/usecases/JwtServiceUseCase"; import { Nullish } from "../../../api/VCLTypes"; import VCLToken from "../../../api/entities/VCLToken"; +import VCLError from "../../../api/entities/error/VCLError"; export default class JwtServiceUseCaseImpl implements JwtServiceUseCase { constructor(private readonly jwtServiceRepository: JwtServiceRepository) {} @@ -18,7 +19,7 @@ export default class JwtServiceUseCaseImpl implements JwtServiceUseCase { try { return await this.jwtServiceRepository.verifyJwt(jwt, publicJwk, remoteCryptoServicesToken); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } diff --git a/packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts index 497d337..28e1ccd 100644 --- a/packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts @@ -2,6 +2,7 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk"; import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor"; import KeyServiceRepository from "../../domain/repositories/KeyServiceRepository"; import KeyServiceUseCase from "../../domain/usecases/KeyServiceUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class KeyServiceUseCaseImpl implements KeyServiceUseCase { constructor(private readonly keyServiceRepository: KeyServiceRepository) {} @@ -11,7 +12,7 @@ export default class KeyServiceUseCaseImpl implements KeyServiceUseCase { try { return await this.keyServiceRepository.generateDidJwk(didJwkDescriptor); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } } diff --git a/packages/sdk/src/impl/data/usecases/OrganizationsUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/OrganizationsUseCaseImpl.ts index bd6b007..949f565 100644 --- a/packages/sdk/src/impl/data/usecases/OrganizationsUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/OrganizationsUseCaseImpl.ts @@ -2,6 +2,7 @@ import VCLOrganizations from "../../../api/entities/VCLOrganizations"; import VCLOrganizationsSearchDescriptor from "../../../api/entities/VCLOrganizationsSearchDescriptor"; import OrganizationsRepository from "../../domain/repositories/OrganizationsRepository"; import OrganizationsUseCase from "../../domain/usecases/OrganizationsUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class OrganizationsUseCaseImpl implements OrganizationsUseCase { constructor(private organizationsRepository: OrganizationsRepository) {} @@ -12,7 +13,7 @@ export default class OrganizationsUseCaseImpl implements OrganizationsUseCase { try { return await this.organizationsRepository.searchForOrganizations(organizationsSearchDescriptor); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } } diff --git a/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts index 13a7f34..e9ff3f4 100644 --- a/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/PresentationRequestUseCaseImpl.ts @@ -39,7 +39,7 @@ export default class PresentationRequestUseCaseImpl ), ); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } diff --git a/packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts index 9d3660d..d2bdf00 100644 --- a/packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts @@ -4,6 +4,7 @@ import VCLSubmissionResult from "../../../api/entities/VCLSubmissionResult"; import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository"; import SubmissionRepository from "../../domain/repositories/SubmissionRepository"; import SubmissionUseCase from "../../domain/usecases/SubmissionUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class SubmissionUseCaseImpl implements SubmissionUseCase { constructor( @@ -28,7 +29,7 @@ export default class SubmissionUseCaseImpl implements SubmissionUseCase { ); return await this.submissionRepository.submit(submission, jwt); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } } diff --git a/packages/sdk/src/impl/data/usecases/VerifiedProfileUseCaseImpl.ts b/packages/sdk/src/impl/data/usecases/VerifiedProfileUseCaseImpl.ts index 8650de8..f50cf40 100644 --- a/packages/sdk/src/impl/data/usecases/VerifiedProfileUseCaseImpl.ts +++ b/packages/sdk/src/impl/data/usecases/VerifiedProfileUseCaseImpl.ts @@ -1,6 +1,7 @@ import VCLVerifiedProfileDescriptor from "../../../api/entities/VCLVerifiedProfileDescriptor"; import VerifiedProfileRepository from "../../domain/repositories/VerifiedProfileRepository"; import VerifiedProfileUseCase from "../../domain/usecases/VerifiedProfileUseCase"; +import VCLError from "../../../api/entities/error/VCLError"; export default class VerifiedProfileUseCaseImpl implements VerifiedProfileUseCase { @@ -13,7 +14,7 @@ export default class VerifiedProfileUseCaseImpl try { return await this.verifiedProfileRepository.getVerifiedProfile(verifiedProfileDescriptor); } catch (error: any) { - throw new Error(error); + throw new VCLError(error); } } } diff --git a/packages/sdk/test/usecases/CredentialManifestUseCase.test.ts b/packages/sdk/test/usecases/CredentialManifestUseCase.test.ts index 4f97322..7f5af24 100644 --- a/packages/sdk/test/usecases/CredentialManifestUseCase.test.ts +++ b/packages/sdk/test/usecases/CredentialManifestUseCase.test.ts @@ -83,8 +83,9 @@ describe("CredentialManifestUseCase Tests", () => { ), new VCLVerifiedProfile(JSON.parse(VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1)) ); + expect(true).toBe(false); } catch (error: any) { - expect(error?.errorCode).toBe(VCLErrorCode.SdkError); + expect(error?.errorCode).toBe(VCLErrorCode.SdkError.toString()); } }); }); \ No newline at end of file diff --git a/packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts b/packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts index 0ebda4e..1115440 100644 --- a/packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts +++ b/packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts @@ -2,9 +2,8 @@ import NetworkServiceSuccess from "../NetworkServiceSuccess"; import ExchangeProgressRepositoryImpl from "../../src/impl/data/repositories/ExchangeProgressRepositoryImpl"; import ExchangeProgressUseCaseImpl from "../../src/impl/data/usecases/ExchangeProgressUseCaseImpl"; import { ExchangeProgressMocks } from "../infrastructure/resources/valid/ExchangeProgressMocks"; -import { Dictionary, VCLErrorCode, VCLExchange, VCLExchangeDescriptor, VCLToken } from "../../src"; -import { mock } from "node:test"; -import { beforeAll, expect } from "@jest/globals"; +import { Dictionary, VCLExchange, VCLExchangeDescriptor, VCLToken } from "../../src"; +import { expect } from "@jest/globals"; describe("ExchangeProgressUseCase Tests", () => { const subject1 = new ExchangeProgressUseCaseImpl( @@ -14,7 +13,7 @@ describe("ExchangeProgressUseCase Tests", () => { ) const subject2 = new ExchangeProgressUseCaseImpl( new ExchangeProgressRepositoryImpl( - new NetworkServiceSuccess({ wrong: 'payload' }) + new NetworkServiceSuccess('') ) ) const exchangeDescriptor = { @@ -30,11 +29,12 @@ describe("ExchangeProgressUseCase Tests", () => { }); test("testGetExchangeProgressFailure", async () => { - try { - await subject1.getExchangeProgress(exchangeDescriptor) - } catch (error: any) { - expect(error.errorCode).toBe(VCLErrorCode.SdkError.toString()) - } + const exchange = await subject2.getExchangeProgress(exchangeDescriptor) + + expect(exchange.id).toBe(undefined) + expect(exchange.type).toBe(undefined) + expect(exchange.disclosureComplete).toBe(undefined) + expect(exchange.exchangeComplete).toBe(undefined) }); const expectedExchange = (exchangeJsonObj: Dictionary): VCLExchange => { diff --git a/packages/sdk/test/usecases/PresentationRequestUseCase.test.ts b/packages/sdk/test/usecases/PresentationRequestUseCase.test.ts index 7040038..e183ab2 100644 --- a/packages/sdk/test/usecases/PresentationRequestUseCase.test.ts +++ b/packages/sdk/test/usecases/PresentationRequestUseCase.test.ts @@ -86,8 +86,9 @@ describe("PresentationRequestUseCase Tests", () => { ), new VCLVerifiedProfile({}) ); + expect(true).toBe(false); } catch (error: any) { - expect(error.errorCode).toBe(VCLErrorCode.SdkError); + expect(error.errorCode).toBe(VCLErrorCode.SdkError.toString()); } }); }); \ No newline at end of file