From 985e330a5ef9851d447ff918ba82504afc51f3fa Mon Sep 17 00:00:00 2001 From: Michael Avoyan Date: Thu, 11 Jul 2024 17:00:44 +0300 Subject: [PATCH] refactor cont --- .../fetchers/GenerateSignedJwtFetcher.ts | 60 ++++++------------- .../fetchers/VerifyJwtFetcher.ts | 12 ++-- 2 files changed, 22 insertions(+), 50 deletions(-) diff --git a/packages/sample-server/src/crypto-services/fetchers/GenerateSignedJwtFetcher.ts b/packages/sample-server/src/crypto-services/fetchers/GenerateSignedJwtFetcher.ts index a4553da..d1dd501 100644 --- a/packages/sample-server/src/crypto-services/fetchers/GenerateSignedJwtFetcher.ts +++ b/packages/sample-server/src/crypto-services/fetchers/GenerateSignedJwtFetcher.ts @@ -8,12 +8,7 @@ import { getJwtSignServiceUrl } from "./Urls"; import { CurrentEnvironment } from "../../GlobalConfig"; import fetcher from "./Fetcher"; -import { - VCLDidJwk, - VCLJwtDescriptor, - Dictionary, - Nullish -} from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src"; +import { Dictionary, Nullish, VCLDidJwk, VCLJwtDescriptor } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src"; export async function generateSignedJwtFetcher( jwtDescriptor: VCLJwtDescriptor, @@ -37,40 +32,21 @@ function generateJwtPayloadToSign( nonce: Nullish, didJwk: VCLDidJwk ): Dictionary { - const retVal: Dictionary = {}; - const header: Dictionary = {}; - const options: Dictionary = {}; const payload: Dictionary = jwtDescriptor.payload ? { ...jwtDescriptor.payload } : {}; - - header[CodingKeys.KeyJwk] = didJwk.publicJwk.valueJson; - header[CodingKeys.KeyKid] = didJwk.kid; - - options[CodingKeys.KeyKeyId] = didJwk.keyId; - - payload[CodingKeys.KeyNonce] = nonce; - payload[CodingKeys.KeyAud] = jwtDescriptor.aud; - payload[CodingKeys.KeyJti] = jwtDescriptor.jti; - payload[CodingKeys.KeyIss] = jwtDescriptor.iss; - - retVal[CodingKeys.KeyHeader] = header; - retVal[CodingKeys.KeyOptions] = options; - retVal[CodingKeys.KeyPayload] = payload; - - return retVal; -} - -const CodingKeys = { - KeyKeyId: "keyId", - KeyKid: "kid", - KeyJwk: "jwk", - KeyIss: "iss", - KeyAud: "aud", - KeyJti: "jti", - KeyNonce: "nonce", - - KeyHeader: "header", - KeyOptions: "options", - KeyPayload: "payload", - - KeyCompactJwt: "compactJwt" -}; \ No newline at end of file + return { + header: { + jwk: didJwk.publicJwk.valueJson, + kid: didJwk.kid + }, + payload: { + ...payload, + nonce: nonce, + aud: jwtDescriptor.aud, + jti: jwtDescriptor.jti, + iss: jwtDescriptor.iss + }, + options: { + keyId: didJwk.keyId + } + }; +} \ No newline at end of file diff --git a/packages/sample-server/src/crypto-services/fetchers/VerifyJwtFetcher.ts b/packages/sample-server/src/crypto-services/fetchers/VerifyJwtFetcher.ts index 853494e..090b0c2 100644 --- a/packages/sample-server/src/crypto-services/fetchers/VerifyJwtFetcher.ts +++ b/packages/sample-server/src/crypto-services/fetchers/VerifyJwtFetcher.ts @@ -14,15 +14,11 @@ export async function verifyJwtFetcher(jwt: VCLJwt, publicJwk: Nullish): Record { - const retVal: Record = {}; - retVal['jwt'] = jwt.encodedJwt; - retVal['publicKey'] = publicJwk?.valueJson || {}; - return retVal; -} -