Skip to content

Commit

Permalink
Merge pull request #30 from velocitycareerlabs/dev-to-rc
Browse files Browse the repository at this point in the history
Dev to rc
  • Loading branch information
michaelavoyan authored Jan 1, 2024
2 parents 8615eb8 + 21122ba commit 5d015cb
Show file tree
Hide file tree
Showing 37 changed files with 103 additions and 73 deletions.
2 changes: 1 addition & 1 deletion packages/sample-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@fastify/autoload": "~5.7.1",
"env-var": "~7.3.0",
"fastify": "~4.15.0",
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.4.0"
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.5.0"
},
"devDependencies": {
"@jest/globals": "~29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@velocitycareerlabs/vnf-nodejs-wallet-sdk",
"version": "0.4.0",
"version": "0.5.0",
"description": "VNF Wallet SDK Nodejs",
"main": "dist/index.js",
"types": "dist/global.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/api/VCL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import VCLCredentialTypes from "./entities/VCLCredentialTypes";
import VCLCredentialTypesUIFormSchema from "./entities/VCLCredentialTypesUIFormSchema";
import VCLCredentialTypesUIFormSchemaDescriptor from "./entities/VCLCredentialTypesUIFormSchemaDescriptor";
import VCLDidJwk from "./entities/VCLDidJwk";
import VCLError from "./entities/VCLError";
import VCLError from "./entities/error/VCLError";
import VCLExchange from "./entities/VCLExchange";
import VCLExchangeDescriptor from "./entities/VCLExchangeDescriptor";
import VCLFinalizeOffersDescriptor from "./entities/VCLFinalizeOffersDescriptor";
import VCLGenerateOffersDescriptor from "./entities/VCLGenerateOffersDescriptor";
import VCLInitializationDescriptor from "./entities/VCLInitializationDescriptor";
import VCLJwkPublic from "./entities/VCLJwkPublic";
import VCLPublicJwk from "./entities/VCLPublicJwk";
import VCLJwt from "./entities/VCLJwt";
import VCLJwtDescriptor from "./entities/VCLJwtDescriptor";
import VCLJwtVerifiableCredentials from "./entities/VCLJwtVerifiableCredentials";
Expand Down Expand Up @@ -80,7 +80,7 @@ export default interface VCL {
verifiedProfileDescriptor: VCLVerifiedProfileDescriptor
): Promise<VCLVerifiedProfile>;

verifyJwt(jwt: VCLJwt, jwkPublic: VCLJwkPublic): Promise<boolean>;
verifyJwt(jwt: VCLJwt, jwkPublic: VCLPublicJwk): Promise<boolean>;

generateSignedJwt(jwtDescriptor: VCLJwtDescriptor): Promise<VCLJwt>;

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/api/entities/VCLPresentationRequest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import VCLDeepLink from "./VCLDeepLink";
import VCLJwkPublic from "./VCLJwkPublic";
import VCLPublicJwk from "./VCLPublicJwk";
import VCLJwt from "./VCLJwt";
import VCLPushDelegate from "./VCLPushDelegate";

export default class VCLPresentationRequest {
constructor(
public readonly jwt: VCLJwt,
public readonly jwkPublic: VCLJwkPublic,
public readonly jwkPublic: VCLPublicJwk,
public readonly deepLink: VCLDeepLink,
public readonly pushDelegate: Nullish<VCLPushDelegate> = null
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ enum Format {
base58 = "base58",
}

export default class VCLJwkPublic {
export default class VCLPublicJwk {
constructor(public valueStr: string, public valueJson: JSONObject) {}
static readonly Format = Format;

public static fromString(valueStr: string) {
return new VCLJwkPublic(valueStr, JSON.parse(valueStr));
return new VCLPublicJwk(valueStr, JSON.parse(valueStr));
}

public static fromJSON(valueJson: JSONObject) {
return new VCLJwkPublic(JSON.stringify(valueJson), valueJson);
return new VCLPublicJwk(JSON.stringify(valueJson), valueJson);
}
}
2 changes: 1 addition & 1 deletion packages/sdk/src/api/entities/VCLResult.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLError from "./VCLError";
import VCLError from "./error/VCLError";

export default class VCLResult<R> {
static Success = class<T> extends VCLResult<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import VCLErrorCode from "./VCLErrorCode";

export default class VCLError extends Error {
payload: Nullish<string> = null;
error: Nullish<string> = null;
errorCode: Nullish<string> = null;
errorCode: string = VCLErrorCode.SdkError.toString();
statusCode: Nullish<number> = null;

constructor(
error: Nullish<string> = null,
errorCode: Nullish<string> = null,
errorCode: string = VCLErrorCode.SdkError.toString(),
message: Nullish<string> = null,
statusCode: Nullish<number> = null
) {
Expand All @@ -23,7 +25,7 @@ export default class VCLError extends Error {
const payloadJson = JSON.parse(payload);
let result = new VCLError(
payloadJson?.[VCLError.KeyError] || null,
payloadJson?.[VCLError.KeyErrorCode] || null,
payloadJson?.[VCLError.KeyErrorCode] || VCLErrorCode.SdkError.toString(),
payloadJson?.[VCLError.KeyMessage] || null,
payloadJson?.[VCLError.KeyStatusCode] || null
);
Expand All @@ -36,16 +38,20 @@ export default class VCLError extends Error {
exception: Error,
statusCode: number | null = null
): VCLError {
let result = new VCLError(null, null, exception.message, statusCode);

let result = new VCLError(
null,
VCLErrorCode.SdkError.toString(),
exception.message,
statusCode
);
return result;
}

get jsonObject(): JSONObject {
return {
[VCLError.KeyPayload]: this.payload,
[VCLError.KeyError]: this.error,
[VCLError.KeyErrorCode]: this.errorCode,
[VCLError.KeyErrorCode]: (this.errorCode || VCLErrorCode.SdkError.toString()),
[VCLError.KeyMessage]: this.message,
[VCLError.KeyStatusCode]: this.statusCode,
};
Expand Down
20 changes: 20 additions & 0 deletions packages/sdk/src/api/entities/error/VCLErrorCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
enum VCLErrorCode {
// Initialization
RemoteServicesUrlsNotFount = "remote_services_urls_not_found",
InjectedServicesNotFount = "injected_services_not_found",
// Credential issuer verification error codes:
CredentialTypeNotRegistered = "credential_type_not_registered",
IssuerRequiresIdentityPermission = "issuer_requires_identity_permission",
IssuerRequiresNotaryPermission = "issuer_requires_notary_permission",
InvalidCredentialSubjectType = "invalid_credential_subject_type",
InvalidCredentialSubjectContext = "invalid_credential_subject_context",
IssuerUnexpectedPermissionFailure = "issuer_unexpected_permission_failure",
// DID consistent with the Deep Link
MismatchedRequestIssuerDid = "mismatched_request_issuer_did",
MismatchedOfferIssuerDid = "mismatched_offer_issuer_did",
MismatchedCredentialIssuerDid = "mismatched_credential_issuer_did",
MismatchedPresentationRequestInspectorDid = "mismatched_presentation_request_inspector_did",
// General error
SdkError = "sdk_error",
}
export default VCLErrorCode;
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ enum VCLStatusCode {
VerificationError = 403,
Undefined = -1,
}

export default VCLStatusCode;
export default VCLStatusCode;
9 changes: 5 additions & 4 deletions packages/sdk/src/impl/VCLImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import VCLCredentialTypes from "../api/entities/VCLCredentialTypes";
import VCLCredentialTypesUIFormSchema from "../api/entities/VCLCredentialTypesUIFormSchema";
import VCLCredentialTypesUIFormSchemaDescriptor from "../api/entities/VCLCredentialTypesUIFormSchemaDescriptor";
import VCLDidJwk from "../api/entities/VCLDidJwk";
import VCLError from "../api/entities/VCLError";
import VCLError from "../api/entities/error/VCLError";
import VCLExchange from "../api/entities/VCLExchange";
import VCLExchangeDescriptor from "../api/entities/VCLExchangeDescriptor";
import VCLFinalizeOffersDescriptor from "../api/entities/VCLFinalizeOffersDescriptor";
import VCLGenerateOffersDescriptor from "../api/entities/VCLGenerateOffersDescriptor";
import VCLIdentificationSubmission from "../api/entities/VCLIdentificationSubmission";
import VCLInitializationDescriptor from "../api/entities/VCLInitializationDescriptor";
import VCLJwkPublic from "../api/entities/VCLJwkPublic";
import VCLPublicJwk from "../api/entities/VCLPublicJwk";
import VCLJwt from "../api/entities/VCLJwt";
import VCLJwtDescriptor from "../api/entities/VCLJwtDescriptor";
import VCLJwtVerifiableCredentials from "../api/entities/VCLJwtVerifiableCredentials";
Expand Down Expand Up @@ -44,6 +44,7 @@ import "./extensions/DateExtensions";
import "./extensions/StringExtensions";
import "./extensions/ListExtensions";
import VCLResult from "../api/entities/VCLResult";
import VCLErrorCode from "../api/entities/error/VCLErrorCode";
export class VCLImpl implements VCL {
static TAG = VCLImpl.name;

Expand Down Expand Up @@ -259,7 +260,7 @@ export class VCLImpl implements VCL {
`did was not found in ${JSON.stringify(
credentialManifestDescriptor
)}`,
null,
VCLErrorCode.SdkError.toString(),
null
);
VCLLog.e(
Expand Down Expand Up @@ -375,7 +376,7 @@ export class VCLImpl implements VCL {
return result!;
};

verifyJwt = async (jwt: VCLJwt, jwkPublic: VCLJwkPublic) => {
verifyJwt = async (jwt: VCLJwt, jwkPublic: VCLPublicJwk) => {
let isVerifiedResult = await this.jwtServiceUseCase.verifyJwt(
jwt,
jwkPublic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import VCLJwtDescriptor from "../../../../api/entities/VCLJwtDescriptor";
import JwtService from "../../../domain/infrastructure/jwt/JwtService";
import crypto from "crypto";
import canonicalize from "canonicalize";
import VCLJwkPublic from "../../../../api/entities/VCLJwkPublic";
import VCLPublicJwk from "../../../../api/entities/VCLPublicJwk";

export default class JwtServiceImpl implements JwtService {
parse(jwt: string): Nullish<SignedJWT> {
Expand Down Expand Up @@ -111,6 +111,6 @@ export default class JwtServiceImpl implements JwtService {

private async generateJwkPublic(kid: string) {
let publicJwk = await this.generateJwkSECP256K1(kid).toPublicJWK();
return VCLJwkPublic.fromJSON(publicJwk);
return VCLPublicJwk.fromJSON(publicJwk);
}
}
2 changes: 1 addition & 1 deletion packages/sdk/src/impl/data/models/CountriesModelImpl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import VCLCountries from "../../../api/entities/VCLCountries";
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLResult from "../../../api/entities/VCLResult";
import CountriesModel from "../../domain/models/CountriesModel";
import CountriesUseCase from "../../domain/usecases/CountriesModelUseCase";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import VCLCredentialTypeSchemas from "../../../api/entities/VCLCredentialTypeSchemas";
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLResult from "../../../api/entities/VCLResult";
import CredentialTypeSchemasModel from "../../domain/models/CredentialTypeSchemasModel";
import CredentialTypeSchemasUseCase from "../../domain/usecases/CredentialTypeSchemasUseCase";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes";
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLResult from "../../../api/entities/VCLResult";
import CredentialTypesModel from "../../domain/models/CredentialTypesModel";
import { CredentialTypesUseCase } from "../../domain/usecases/CredentialTypesUseCase";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import VCLCredentialManifest from "../../../api/entities/VCLCredentialManifest";
import VCLCredentialManifestDescriptor from "../../../api/entities/VCLCredentialManifestDescriptor";
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLResult from "../../../api/entities/VCLResult";
import NetworkService from "../../domain/infrastructure/network/NetworkService";
import CredentialManifestRepository from "../../domain/repositories/CredentialManifestRepository";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import VCLCredentialType from "../../../api/entities/VCLCredentialType";
import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes";
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLResult from "../../../api/entities/VCLResult";
import NetworkService from "../../domain/infrastructure/network/NetworkService";
import CredentialTypesRepository from "../../domain/repositories/CredentialTypesRepository";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLExchange from "../../../api/entities/VCLExchange";
import VCLExchangeDescriptor from "../../../api/entities/VCLExchangeDescriptor";
import VCLResult from "../../../api/entities/VCLResult";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLFinalizeOffersDescriptor from "../../../api/entities/VCLFinalizeOffersDescriptor";
import VCLJwt from "../../../api/entities/VCLJwt";
import VCLResult from "../../../api/entities/VCLResult";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLGenerateOffersDescriptor from "../../../api/entities/VCLGenerateOffersDescriptor";
import VCLOffers from "../../../api/entities/VCLOffers";
import VCLResult from "../../../api/entities/VCLResult";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import VCLDidJwk from "../../../api/entities/VCLDidJwk";
import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor";
import VCLError from "../../../api/entities/VCLError";
import VCLJwkPublic from "../../../api/entities/VCLJwkPublic";
import VCLError from "../../../api/entities/error/VCLError";
import VCLPublicJwk from "../../../api/entities/VCLPublicJwk";
import VCLJwt from "../../../api/entities/VCLJwt";
import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor";
import VCLResult from "../../../api/entities/VCLResult";
Expand All @@ -25,7 +25,7 @@ export default class JwtServiceRepositoryImpl implements JwtServiceRepository {
}
async verifyJwt(
jwt: VCLJwt,
jwkPublic: VCLJwkPublic
jwkPublic: VCLPublicJwk
): Promise<VCLResult<boolean>> {
try {
let it = await this.jwtService.verify(jwt, jwkPublic.valueStr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLOrganization from "../../../api/entities/VCLOrganization";
import VCLOrganizations from "../../../api/entities/VCLOrganizations";
import VCLOrganizationsSearchDescriptor from "../../../api/entities/VCLOrganizationsSearchDescriptor";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLPresentationRequest from "../../../api/entities/VCLPresentationRequest";
import VCLPresentationRequestDescriptor from "../../../api/entities/VCLPresentationRequestDescriptor";
import VCLResult from "../../../api/entities/VCLResult";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLJwkPublic from "../../../api/entities/VCLJwkPublic";
import VCLPublicJwk from "../../../api/entities/VCLPublicJwk";
import VCLResult from "../../../api/entities/VCLResult";
import NetworkService from "../../domain/infrastructure/network/NetworkService";
import ResolveKidRepository from "../../domain/repositories/ResolveKidRepository";
Expand All @@ -8,10 +8,10 @@ import Urls, { HeaderKeys, HeaderValues } from "./Urls";
export default class ResolveKidRepositoryImpl implements ResolveKidRepository {
constructor(private readonly networkService: NetworkService) {}

async getPublicKey(kid: string): Promise<VCLResult<VCLJwkPublic>> {
async getPublicKey(kid: string): Promise<VCLResult<VCLPublicJwk>> {
let result = await this.networkService.sendRequest({
endpoint:
Urls.ResolveKid + kid + `?format=${VCLJwkPublic.Format.jwk}`,
Urls.ResolveKid + kid + `?format=${VCLPublicJwk.Format.jwk}`,
method: HttpMethod.GET,
headers: {
[HeaderKeys.XVnfProtocolVersion]:
Expand All @@ -28,7 +28,7 @@ export default class ResolveKidRepositoryImpl implements ResolveKidRepository {
}

return new VCLResult.Success(
VCLJwkPublic.fromJSON(publicKeyResponse!.payload)
VCLPublicJwk.fromJSON(publicKeyResponse!.payload)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLExchange from "../../../api/entities/VCLExchange";
import VCLJwt from "../../../api/entities/VCLJwt";
import VCLResult from "../../../api/entities/VCLResult";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import VCLCredentialManifest from "../../../api/entities/VCLCredentialManifest";
import VCLCredentialManifestDescriptor from "../../../api/entities/VCLCredentialManifestDescriptor";
import VCLError from "../../../api/entities/VCLError";
import VCLJwkPublic from "../../../api/entities/VCLJwkPublic";
import VCLError from "../../../api/entities/error/VCLError";
import VCLPublicJwk from "../../../api/entities/VCLPublicJwk";
import VCLJwt from "../../../api/entities/VCLJwt";
import VCLResult from "../../../api/entities/VCLResult";
import CredentialManifestRepository from "../../domain/repositories/CredentialManifestRepository";
Expand Down Expand Up @@ -54,7 +54,7 @@ export default class CredentialManifestUseCaseImpl
}

async onResolvePublicKeySuccess(
jwkPublic: VCLJwkPublic,
jwkPublic: VCLPublicJwk,
jwt: VCLJwt,
credentialManifestDescriptor: VCLCredentialManifestDescriptor
): Promise<VCLResult<VCLCredentialManifest>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VCLError from "../../../api/entities/VCLError";
import VCLError from "../../../api/entities/error/VCLError";
import VCLFinalizeOffersDescriptor from "../../../api/entities/VCLFinalizeOffersDescriptor";
import VCLJwt from "../../../api/entities/VCLJwt";
import VCLJwtVerifiableCredentials from "../../../api/entities/VCLJwtVerifiableCredentials";
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import VCLDidJwk from "../../../api/entities/VCLDidJwk";
import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor";
import VCLJwkPublic from "../../../api/entities/VCLJwkPublic";
import VCLPublicJwk from "../../../api/entities/VCLPublicJwk";
import VCLJwt from "../../../api/entities/VCLJwt";
import VCLJwtDescriptor from "../../../api/entities/VCLJwtDescriptor";
import VCLResult from "../../../api/entities/VCLResult";
Expand All @@ -14,7 +14,7 @@ export default class JwtServiceUseCaseImpl implements JwtServiceUseCase {
return this.jwtServiceRepository.generateDidJwk(didJwkDescriptor);
}

verifyJwt(jwt: VCLJwt, jwkPublic: VCLJwkPublic) {
verifyJwt(jwt: VCLJwt, jwkPublic: VCLPublicJwk) {
return this.jwtServiceRepository.verifyJwt(jwt, jwkPublic);
}
generateSignedJwt(jwtDescriptor: VCLJwtDescriptor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import VCLError from "../../../api/entities/VCLError";
import VCLJwkPublic from "../../../api/entities/VCLJwkPublic";
import VCLError from "../../../api/entities/error/VCLError";
import VCLPublicJwk from "../../../api/entities/VCLPublicJwk";
import VCLJwt from "../../../api/entities/VCLJwt";
import VCLPresentationRequest from "../../../api/entities/VCLPresentationRequest";
import VCLPresentationRequestDescriptor from "../../../api/entities/VCLPresentationRequestDescriptor";
Expand Down Expand Up @@ -81,7 +81,7 @@ export default class PresentationRequestUseCaseImpl
}

async onResolvePublicKeySuccess(
jwkPublic: VCLJwkPublic,
jwkPublic: VCLPublicJwk,
jwt: VCLJwt,
presentationRequestDescriptor: VCLPresentationRequestDescriptor
): Promise<VCLResult<VCLPresentationRequest>> {
Expand Down
Loading

0 comments on commit 5d015cb

Please sign in to comment.