Skip to content

Commit

Permalink
v0.9.5 - proof management (person binding)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelavoyan committed Jun 3, 2024
1 parent d457f21 commit 1da809f
Show file tree
Hide file tree
Showing 30 changed files with 530 additions and 97 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ module.exports = {
'no-undef': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'unused-imports/no-unused-vars': 'error',
// '@typescript-eslint/no-namespace': 'off',
}
};
2 changes: 1 addition & 1 deletion packages/sample-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@fastify/autoload": "~5.7.1",
"env-var": "~7.3.0",
"fastify": "~4.15.0",
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.9.4"
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.9.5"
},
"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.9.4",
"version": "0.9.5",
"description": "VNF Wallet SDK Nodejs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/api/VCLEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
enum VCLEnvironment {
PROD = "prod",
STAGING = "staging",
QA = "qa",
DEV = "dev",
Prod = "prod",
Staging = "staging",
Qa = "qa",
Dev = "dev",
}

export default VCLEnvironment;
4 changes: 4 additions & 0 deletions packages/sdk/src/api/VCLXVnfProtocolVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum VCLXVnfProtocolVersion {
XVnfProtocolVersion1 = "1.0",
XVnfProtocolVersion2 = "2.0"
}
34 changes: 22 additions & 12 deletions packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dictionary } from "../VCLTypes";
import { Dictionary, Nullish } from "../VCLTypes";
import VCLCredentialManifest from "./VCLCredentialManifest";
import VCLJwt from "./VCLJwt";

Expand All @@ -10,32 +10,42 @@ export default class VCLFinalizeOffersDescriptor {
public readonly rejectedOfferIds: string[]
) {
}

get exchangeId() {
return this.credentialManifest.exchangeId;
get didJwk() {
return this.credentialManifest.didJwk
}
get remoteCryptoServicesToken() {
return this.credentialManifest.remoteCryptoServicesToken
}

get finalizeOffersUri() {
return this.credentialManifest.finalizeOffersUri;
}

get did() {
return this.credentialManifest.did;
}
get issuerId() {
return this.credentialManifest.issuerId
}
get aud() {
return this.credentialManifest.aud
}
get exchangeId() {
return this.credentialManifest.exchangeId
}

payload: Dictionary<any> = {
[VCLFinalizeOffersDescriptor.KeyExchangeId]: this.exchangeId,
[VCLFinalizeOffersDescriptor.KeyApprovedOfferIds]: this.approvedOfferIds,
[VCLFinalizeOffersDescriptor.KeyRejectedOfferIds]: this.rejectedOfferIds,
};

generateRequestBody(jwt: VCLJwt): Dictionary<any> {
generateRequestBody(proof: Nullish<VCLJwt>=null): Dictionary<any> {
const retVal = this.payload;
const proof: any = {};
proof[VCLFinalizeOffersDescriptor.KeyProofType] =
VCLFinalizeOffersDescriptor.KeyJwt;
proof[VCLFinalizeOffersDescriptor.KeyJwt] = jwt.signedJwt.serialize();
retVal[VCLFinalizeOffersDescriptor.KeyProof] = proof;
const proofJson: any = {};
if (proof) {
proofJson[VCLFinalizeOffersDescriptor.KeyProofType] = VCLFinalizeOffersDescriptor.KeyJwt;
proofJson[VCLFinalizeOffersDescriptor.KeyJwt] = proof.signedJwt.serialize();
retVal[VCLFinalizeOffersDescriptor.KeyProof] = proofJson
}
return retVal;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import VCLEnvironment from "../../VCLEnvironment";
import VCLCryptoServicesDescriptor from "./VCLCryptoServicesDescriptor";
import { VCLXVnfProtocolVersion } from "../../VCLXVnfProtocolVersion";

export default class VCLInitializationDescriptor {
constructor(
public readonly environment: VCLEnvironment = VCLEnvironment.PROD,
public readonly environment: VCLEnvironment = VCLEnvironment.Prod,
public readonly xVnfProtocolVersion: VCLXVnfProtocolVersion = VCLXVnfProtocolVersion.XVnfProtocolVersion1,
public readonly cryptoServicesDescriptor: VCLCryptoServicesDescriptor
) {}
}
10 changes: 6 additions & 4 deletions packages/sdk/src/impl/GlobalConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import VCLEnvironment from "../api/VCLEnvironment";
import { VCLXVnfProtocolVersion } from "../api/VCLXVnfProtocolVersion";

export default class GlobalConfig {
static readonly IsDebug = true;
static CurrentEnvironment = VCLEnvironment.PROD;
static IsDebugOn = false;
static CurrentEnvironment = VCLEnvironment.Prod;
static XVnfProtocolVersion = VCLXVnfProtocolVersion.XVnfProtocolVersion1;
static readonly LogTagPrefix = "VCL ";
static IsToLoadFromCacheInitialization = false;
static get isLoggerOn() {
return this.CurrentEnvironment !== VCLEnvironment.PROD;
static get IsLoggerOn() {
return (this.CurrentEnvironment != VCLEnvironment.Staging && this.CurrentEnvironment != VCLEnvironment.Prod) || this.IsDebugOn;
}
}
9 changes: 8 additions & 1 deletion packages/sdk/src/impl/VCLImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export class VCLImpl implements VCL {
async initialize(
initializationDescriptor: VCLInitializationDescriptor
): Promise<Nullish<VCLError>> {
GlobalConfig.CurrentEnvironment = initializationDescriptor.environment;

this.initGlobalConfigurations();

this.initializationDescriptor = initializationDescriptor;
this.initializationWatcher = new InitializationWatcher(
VCLImpl.ModelsToInitializeAmount
Expand Down Expand Up @@ -156,6 +158,11 @@ export class VCLImpl implements VCL {
}
}

private initGlobalConfigurations() {
GlobalConfig.CurrentEnvironment = this.initializationDescriptor.environment
GlobalConfig.XVnfProtocolVersion = this.initializationDescriptor.xVnfProtocolVersion
}

private initializeUseCases() {
this.verifiedProfileUseCase =
VclBlocksProvider.provideVerifiedProfileUseCase();
Expand Down
53 changes: 20 additions & 33 deletions packages/sdk/src/impl/VclBlocksProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import VCLCredentialTypes from "../api/entities/VCLCredentialTypes";
import VCLCryptoServicesDescriptor from "../api/entities/initialization/VCLCryptoServicesDescriptor";
import VCLJwtSignService from "../api/jwt/VCLJwtSignService";
import VCLJwtVerifyService from "../api/jwt/VCLJwtVerifyService";
import NetworkServiceImpl from "./data/infrastructure/network/NetworkServiceImpl";
import CountriesModelImpl from "./data/models/CountriesModelImpl";
import CredentialTypeSchemasModelImpl from "./data/models/CredentialTypeSchemasModelImpl";
Expand Down Expand Up @@ -51,34 +49,20 @@ import VerifiedProfileUseCase from "./domain/usecases/VerifiedProfileUseCase";
import KeyServiceUseCase from "./domain/usecases/KeyServiceUseCase";
import KeyServiceUseCaseImpl from "./data/usecases/KeyServiceUseCaseImpl";
import KeyServiceRepositoryImpl from "./data/repositories/KeyServiceRepositoryImpl";
import CredentialIssuerVerifierImpl from "./data/verifiers/CredentialIssuerVerifierImpl";
import CredentialDidVerifierImpl from "./data/verifiers/CredentialDidVerifierImpl";
import CredentialsByDeepLinkVerifierImpl from "./data/verifiers/CredentialsByDeepLinkVerifierImpl";

export default class VclBlocksProvider {
private static chooseKeyService(
cryptoServicesDescriptor: VCLCryptoServicesDescriptor
) {
return cryptoServicesDescriptor.keyService;
}
private static chooseJwtSignService(
cryptoServicesDescriptor: VCLCryptoServicesDescriptor
): VCLJwtSignService {
return cryptoServicesDescriptor.jwtSignService;
}

private static chooseJwtVerifyService(
cryptoServicesDescriptor: VCLCryptoServicesDescriptor
): VCLJwtVerifyService {
return cryptoServicesDescriptor.jwtVerifyService;
}

static providePresentationRequestUseCase(
cryptoServicesDescriptor: VCLCryptoServicesDescriptor
): PresentationRequestUseCase {
return new PresentationRequestUseCaseImpl(
new PresentationRequestRepositoryImpl(new NetworkServiceImpl()),
new ResolveKidRepositoryImpl(new NetworkServiceImpl()),
new JwtServiceRepositoryImpl(
this.chooseJwtSignService(cryptoServicesDescriptor),
this.chooseJwtVerifyService(cryptoServicesDescriptor)
cryptoServicesDescriptor.jwtSignService,
cryptoServicesDescriptor.jwtVerifyService
)
);
}
Expand All @@ -94,8 +78,8 @@ export default class VclBlocksProvider {
): JwtServiceUseCase {
return new JwtServiceUseCaseImpl(
new JwtServiceRepositoryImpl(
this.chooseJwtSignService(cryptoServicesDescriptor),
this.chooseJwtVerifyService(cryptoServicesDescriptor)
cryptoServicesDescriptor.jwtSignService,
cryptoServicesDescriptor.jwtVerifyService
)
);
}
Expand All @@ -107,8 +91,8 @@ export default class VclBlocksProvider {
new CredentialManifestRepositoryImpl(new NetworkServiceImpl()),
new ResolveKidRepositoryImpl(new NetworkServiceImpl()),
new JwtServiceRepositoryImpl(
this.chooseJwtSignService(cryptoServicesDescriptor),
this.chooseJwtVerifyService(cryptoServicesDescriptor)
cryptoServicesDescriptor.jwtSignService,
cryptoServicesDescriptor.jwtVerifyService
)
);
}
Expand All @@ -121,8 +105,8 @@ export default class VclBlocksProvider {
new NetworkServiceImpl()
),
new JwtServiceRepositoryImpl(
this.chooseJwtSignService(cryptoServicesDescriptor),
this.chooseJwtVerifyService(cryptoServicesDescriptor)
cryptoServicesDescriptor.jwtSignService,
cryptoServicesDescriptor.jwtVerifyService
)
);
}
Expand All @@ -139,9 +123,12 @@ export default class VclBlocksProvider {
return new FinalizeOffersUseCaseImpl(
new FinalizeOffersRepositoryImpl(new NetworkServiceImpl()),
new JwtServiceRepositoryImpl(
this.chooseJwtSignService(cryptoServicesDescriptor),
this.chooseJwtVerifyService(cryptoServicesDescriptor)
)
cryptoServicesDescriptor.jwtSignService,
cryptoServicesDescriptor.jwtVerifyService
),
new CredentialIssuerVerifierImpl(),
new CredentialDidVerifierImpl(),
new CredentialsByDeepLinkVerifierImpl()
);
}

Expand All @@ -153,8 +140,8 @@ export default class VclBlocksProvider {
new NetworkServiceImpl()
),
new JwtServiceRepositoryImpl(
this.chooseJwtSignService(cryptoServicesDescriptor),
this.chooseJwtVerifyService(cryptoServicesDescriptor)
cryptoServicesDescriptor.jwtSignService,
cryptoServicesDescriptor.jwtVerifyService
)
);
}
Expand Down Expand Up @@ -213,7 +200,7 @@ export default class VclBlocksProvider {
): KeyServiceUseCase {
return new KeyServiceUseCaseImpl(
new KeyServiceRepositoryImpl(
VclBlocksProvider.chooseKeyService(cryptoServicesDescriptor)
cryptoServicesDescriptor.keyService
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ export class FinalizeOffersRepositoryImpl implements FinalizeOffersRepository {

async finalizeOffers(
finalizeOffersDescriptor: VCLFinalizeOffersDescriptor,
sessionToken: VCLToken
sessionToken: VCLToken,
proof: Nullish<VCLJwt> = null,
): Promise<VCLJwt[]> {
const finalizedOffersResponse = await this.networkService.sendRequest({
useCaches: false,
endpoint: finalizeOffersDescriptor.finalizeOffersUri,
body: finalizeOffersDescriptor.payload,
body: finalizeOffersDescriptor.generateRequestBody(proof),
headers: {
[HeaderKeys.HeaderKeyAuthorization]: `${HeaderKeys.HeaderValuePrefixBearer} ${sessionToken.value}`,
[HeaderKeys.XVnfProtocolVersion]:
Expand Down
13 changes: 8 additions & 5 deletions packages/sdk/src/impl/data/repositories/Urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import GlobalConfig from "../../GlobalConfig";
export default class Urls {
private static get EnvironmentPrefix(): string {
return {
[VCLEnvironment.PROD]: "",
[VCLEnvironment.STAGING]: "staging",
[VCLEnvironment.QA]: "qa",
[VCLEnvironment.DEV]: "dev",
[VCLEnvironment.Prod]: "",
[VCLEnvironment.Staging]: "staging",
[VCLEnvironment.Qa]: "qa",
[VCLEnvironment.Dev]: "dev",
}[GlobalConfig.CurrentEnvironment];
}
private static get BaseUrlServices(): string {
return `https://${Urls.EnvironmentPrefix}registrar.velocitynetwork.foundation`;
// return `https://${Urls.EnvironmentPrefix}walletapi.velocitycareerlabs.io`;
}

static get CredentialTypes(): string {
Expand Down Expand Up @@ -49,5 +50,7 @@ export class HeaderKeys {
}

export class HeaderValues {
static readonly XVnfProtocolVersion = "1.0";
static get XVnfProtocolVersion() {
return GlobalConfig.XVnfProtocolVersion.toString();
}
}
Loading

0 comments on commit 1da809f

Please sign in to comment.