Skip to content

Commit

Permalink
Merge pull request #81 from velocitycareerlabs/VL-7921-remove-handleR…
Browse files Browse the repository at this point in the history
…esult-method

chore: remove `VCLResult` and use `Promise` only + fixes
  • Loading branch information
michaelavoyan authored May 29, 2024
2 parents 6577318 + e910015 commit 1730a35
Show file tree
Hide file tree
Showing 130 changed files with 1,366 additions and 1,265 deletions.
12 changes: 7 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
};
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
16 changes: 8 additions & 8 deletions packages/sample-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions packages/sample-server/src/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars
interface String {
getQueryParameters(): Map<string, string>;
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<T> {
toJsonArray(): any[];
}

// eslint-disable-next-line unused-imports/no-unused-vars
interface Date {
addDaysToNow(days: number): Date;
equalsTo(date: Date): boolean;
}
1 change: 0 additions & 1 deletion packages/sample-server/src/routes/users/getUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<getUserRequestInterface>(
"/:userId",
{
Expand Down
63 changes: 14 additions & 49 deletions packages/sample-server/test/initalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -83,32 +76,4 @@ describe("initalization flow", () => {
afghanistanRegions?.all[2].code == AfghanistanRegion3Code
).toBeTruthy();
}, 400000);
});

class VCLKeyServiceEmptyImpl implements VCLKeyService {
generateDidJwk(didJwkDescriptor: VCLDidJwkDescriptor): Promise<VCLResult<VCLDidJwk>> {
return new Promise<VCLResult<VCLDidJwk>>((resolve, reject) => {
resolve(new VCLResult<VCLDidJwk>());
});
}
}

class VCLJwtSignServiceEmptyImpl implements VCLJwtSignService {
sign(
jwtDescriptor: VCLJwtDescriptor,
didJwk: VCLDidJwk,
nonce: Nullish<string>
): Promise<VCLResult<VCLJwt>> {
return new Promise<VCLResult<VCLJwt>>((resolve, reject) => {
resolve(new VCLResult<VCLJwt>());
});
}
}

class VCLJwtVerifyServiceEmptyImpl implements VCLJwtVerifyService {
verify(jwt: VCLJwt, publicJwk: Nullish<VCLPublicJwk>): Promise<VCLResult<boolean>> {
return new Promise<VCLResult<boolean>>((resolve, reject) => {
resolve(new VCLResult<boolean>());
});
}
}
});
20 changes: 20 additions & 0 deletions packages/sample-server/test/mocks/DidJwkMocks.ts
Original file line number Diff line number Diff line change
@@ -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 }
22 changes: 22 additions & 0 deletions packages/sample-server/test/mocks/jwt/JwtSignServiceMock.ts
Original file line number Diff line number Diff line change
@@ -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<string> = null) {}

async sign(
jwtDescriptor: VCLJwtDescriptor,
didJwk: VCLDidJwk,
nonce: Nullish<string>,
remoteCryptoServicesToken: Nullish<VCLToken>
): Promise<VCLJwt> {
return VCLJwt.fromEncodedJwt(this.successValue || '');
}
}
9 changes: 9 additions & 0 deletions packages/sample-server/test/mocks/jwt/JwtVerifyServiceMock.ts
Original file line number Diff line number Diff line change
@@ -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<VCLPublicJwk>): Promise<boolean> {
return true;
}
}
10 changes: 10 additions & 0 deletions packages/sample-server/test/mocks/key/KeyServiceMock.ts
Original file line number Diff line number Diff line change
@@ -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<VCLDidJwk> {
return DidJwkMocks.DidJwk
}
}
11 changes: 5 additions & 6 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions packages/sdk/src/api/VCL.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";
Expand All @@ -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(
Expand Down Expand Up @@ -60,12 +56,12 @@ export default interface VCL {

checkForOffers(
generateOffersDescriptor: VCLGenerateOffersDescriptor,
token: VCLToken
sessionToken: VCLToken,
): Promise<VCLOffers>;

finalizeOffers(
finalizeOffersDescriptor: VCLFinalizeOffersDescriptor,
token: VCLToken
sessionToken: VCLToken,
): Promise<VCLJwtVerifiableCredentials>;

getCredentialTypesUIFormSchema(
Expand Down
30 changes: 30 additions & 0 deletions packages/sdk/src/api/entities/VCLCredentialManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> | undefined;
const issuerId = issuerMap?.[VCLCredentialManifest.KeyId] as string | undefined;

return issuerId ?? "";
}



get exchangeId(): string {
return this.jwt.payload[VCLCredentialManifest.KeyExchangeId] ?? "";
}
Expand Down Expand Up @@ -59,6 +82,13 @@ export default class VCLCredentialManifest {
);
}

private retrieveAud(): string {
const keyMetadata = this.jwt.payload[VCLCredentialManifest.KeyMetadata] ?? {};
const finalizeOffersUri = (keyMetadata as Record<string, any>)[VCLCredentialManifest.KeyFinalizeOffersUri] ?? "";
return finalizeOffersUri.split("/issue/")[0];
}


// CodingKeys
static readonly KeyIssuingRequest: string = "issuing_request";
static readonly KeyId: string = "id";
Expand Down
Loading

0 comments on commit 1730a35

Please sign in to comment.