Skip to content

Commit

Permalink
Merge pull request #60 from velocitycareerlabs/VL-7723
Browse files Browse the repository at this point in the history
v0.8.16 - refactor APIS, JSONObject (any) to real Dictionary<k,v>
  • Loading branch information
michaelavoyan authored May 7, 2024
2 parents 64094fc + 514c106 commit 1ebc0d4
Show file tree
Hide file tree
Showing 71 changed files with 164 additions and 172 deletions.
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.8.15"
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.8.16"
},
"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.8.15",
"version": "0.8.16",
"description": "VNF Wallet SDK Nodejs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/api/VCL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import VCLSubmissionResult from "./entities/VCLSubmissionResult";
import VCLToken from "./entities/VCLToken";
import VCLVerifiedProfile from "./entities/VCLVerifiedProfile";
import VCLVerifiedProfileDescriptor from "./entities/VCLVerifiedProfileDescriptor";
import { Nullish } from "../types";
import { Nullish } from "./VCLTypes";

export default interface VCL {
initialize(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VCLImpl } from "./impl/VCLImpl";
import { VCLImpl } from "../impl/VCLImpl";

export default class VCLProvider {
private static vclInstance: VCLImpl;
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/src/api/VCLSignatureAlgorithm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum VCLSignatureAlgorithm {
ES256 = "P-256",
SECP256k1 = "secp256k1"
}

export default VCLSignatureAlgorithm;
3 changes: 3 additions & 0 deletions packages/sdk/src/api/VCLTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type Nullish<T> = T | null | undefined;

export type Dictionary<T> = Record<string, T>;
2 changes: 1 addition & 1 deletion packages/sdk/src/api/entities/VCLCountries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLCountry from "./VCLCountry";

class VCLCountries {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/api/entities/VCLCountry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Nullish } from "../../types";
import { Dictionary, Nullish } from "../VCLTypes";
import VCLPlace from "./VCLPlace";
import VCLRegions from "./VCLRegions";

export default class VCLCountry extends VCLPlace {
constructor(
public payload: JSONObject,
public payload: Dictionary<any>,
public code: string,
public name: string,
public regions: Nullish<VCLRegions>
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/api/entities/VCLCredentialManifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLJwt from "./VCLJwt";
import VCLVerifiedProfile from "./VCLVerifiedProfile";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLIssuingType from "./VCLIssuingType";
import VCLPushDelegate from "./VCLPushDelegate";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLCredentialManifestDescriptor from "./VCLCredentialManifestDescriptor";
import VCLDeepLink from "./VCLDeepLink";
import VCLIssuingType from "./VCLIssuingType";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLCredentialManifestDescriptor from "./VCLCredentialManifestDescriptor";
import VCLIssuingType from "./VCLIssuingType";
import VCLPushDelegate from "./VCLPushDelegate";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLCredentialManifestDescriptor from "./VCLCredentialManifestDescriptor";
import VCLIssuingType from "./VCLIssuingType";
import VCLService from "./VCLService";
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/api/entities/VCLCredentialType.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Nullish } from "../../types";
import { Dictionary, Nullish } from "../VCLTypes";

export default class VCLCredentialType {
constructor(
public payload: JSONObject,
public payload: Dictionary<any>,
public id: Nullish<string>,
public schema: Nullish<string>,
public createdAt: Nullish<string>,
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/src/api/entities/VCLCredentialTypeSchema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Dictionary } from "../VCLTypes";

export default class VCLCredentialTypeSchema {
constructor(public payload: JSONObject) {}
constructor(public payload: Dictionary<any>) {}
}
2 changes: 1 addition & 1 deletion packages/sdk/src/api/entities/VCLCredentialTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLCredentialType from "./VCLCredentialType";

export default class VCLCredentialTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Dictionary } from "../VCLTypes";

export default class VCLCredentialTypesUIFormSchema {
constructor(public payload: JSONObject) {}
constructor(public payload: Dictionary<any>) {}
// CodingKeys
static readonly KeyAddressRegion = "addressRegion";
static readonly KeyAddressCountry = "addressCountry";
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/api/entities/VCLDeepLink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "../../impl/extensions/StringExtensions";
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";

export default class VCLDeepLink {
public requestUri: Nullish<string>;
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/src/api/entities/VCLDidDocument.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Dictionary } from "../VCLTypes";

export default class VCLDidDocument {
constructor(public payload: JSONObject) {}
constructor(public payload: Dictionary<any>) {}
}
9 changes: 8 additions & 1 deletion packages/sdk/src/api/entities/VCLDidJwkDescriptor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { Nullish } from "src/api/VCLTypes";
import VCLToken from "./VCLToken";
import VCLSignatureAlgorithm from "../VCLSignatureAlgorithm";

export default class VCLDidJwkDescriptor {
constructor(public kid: string) {}
constructor(
public signatureAlgorithm: VCLSignatureAlgorithm = VCLSignatureAlgorithm.ES256,
public remoteCryptoServicesToken: Nullish<VCLToken> = null
) {}
}
31 changes: 3 additions & 28 deletions packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
/*
data class VCLFinalizeOffersDescriptor(
val credentialManifest: VCLCredentialManifest,
val approvedOfferIds: List<String>,
val rejectedOfferIds: List<String>
) {
val payload: JSONObject =
JSONObject()
.putOpt(KeyExchangeId, exchangeId)
.putOpt(KeyApprovedOfferIds, approvedOfferIds.toJsonArray())
.putOpt(KeyRejectedOfferIds, rejectedOfferIds.toJsonArray())
val did: String get() = credentialManifest.did
val exchangeId: String get() = credentialManifest.exchangeId
val finalizeOffersUri: String get() = credentialManifest.finalizeOffersUri
companion object CodingKeys {
const val KeyExchangeId = "exchangeId"
const val KeyApprovedOfferIds = "approvedOfferIds"
const val KeyRejectedOfferIds = "rejectedOfferIds"
}
}
*/

import { Dictionary } from "../VCLTypes";
import VCLCredentialManifest from "./VCLCredentialManifest";
import VCLJwt from "./VCLJwt";

Expand All @@ -46,15 +21,15 @@ export default class VCLFinalizeOffersDescriptor {
return this.credentialManifest.did;
}

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

generateRequestBody(jwt: VCLJwt): JSONObject {
generateRequestBody(jwt: VCLJwt): Dictionary<any> {
const retVal = this.payload;
const proof: any = {};
proof[VCLFinalizeOffersDescriptor.KeyProofType] =
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/api/entities/VCLGenerateOffersDescriptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Dictionary, Nullish } from "../VCLTypes";
import VCLCredentialManifest from "./VCLCredentialManifest";
import VCLVerifiableCredential from "./VCLVerifiableCredential";

Expand All @@ -10,7 +10,7 @@ export default class VCLGenerateOffersDescriptor {
public readonly identificationVerifiableCredentials: VCLVerifiableCredential[]
) {}

payload: JSONObject = {
payload: Dictionary<any> = {
[VCLGenerateOffersDescriptor.KeyExchangeId]: this.exchangeId,
[VCLGenerateOffersDescriptor.KeyTypes]: this.types,
[VCLGenerateOffersDescriptor.KeyOfferHashes]: this.offerHashes,
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/api/entities/VCLJwt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Dictionary, Nullish } from "../VCLTypes";

export default class VCLJwt {
public encodedJwt: Nullish<string>;
Expand Down Expand Up @@ -27,17 +27,17 @@ export default class VCLJwt {
return (this.header.kid || this.jwk.kid) || ""
}

get jwk(): JSONObject {
get jwk(): Dictionary<any> {
return this.header.jwk || JSON.parse("{}")
}

get header(): JSONObject {
get header(): Dictionary<any> {
const buff = Buffer.from(this.signedJwt.header, "base64");
const text = buff.toString("utf-8");
return JSON.parse(text || "{}");
}

get payload(): JSONObject {
get payload(): Dictionary<any> {
const buff = Buffer.from(this.signedJwt.payload, "base64");
const text = buff.toString("utf-8");
return JSON.parse(text || "{}");
Expand Down
29 changes: 23 additions & 6 deletions packages/sdk/src/api/entities/VCLJwtDescriptor.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { randomUUID } from "crypto";
import VCLDidJwk from "./VCLDidJwk";
import { Nullish } from "../../types";
import { Dictionary, Nullish } from "../VCLTypes";

export default class VCLJwtDescriptor {
constructor(
public payload: JSONObject,
public iss: string,
/**
* payload is Json formatted payload
* @type Nullish<Dictionary<any>>
* @public
*/
public payload: Nullish<Dictionary<any>>,
/**
* jti is JWT ID
* @type string
* @public
*/
public jti: string = randomUUID().toString(),
public keyId: Nullish<string>,
public didJwk: Nullish<VCLDidJwk> = null,
/**
* iss is the did of the wallet owner
* @type string
* @public
*/
public iss: string,
/**
* aud is the issuer DID
* @type string
* @public
*/
public aud: Nullish<string> = null
) {}
}
3 changes: 2 additions & 1 deletion packages/sdk/src/api/entities/VCLOffers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Dictionary } from "src/api/VCLTypes";
import VCLToken from "./VCLToken";

export default class VCLOffers {
constructor(
public readonly all: JSONObject[],
public readonly all: Dictionary<any>[],
public readonly responseCode: number,
public readonly token: VCLToken
) {}
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/api/entities/VCLOrganization.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Dictionary } from "../VCLTypes";
import VCLServiceCredentialAgentIssuer from "./VCLServiceCredentialAgentIssuer";

export default class VCLOrganization {
Expand All @@ -6,14 +7,14 @@ export default class VCLOrganization {
get serviceCredentialAgentIssuers(): VCLServiceCredentialAgentIssuer[] {
return this.parseServiceCredentialAgentIssuers();
}
constructor(public readonly payload: JSONObject) {}
constructor(public readonly payload: Dictionary<any>) {}

private parseServiceCredentialAgentIssuers(): VCLServiceCredentialAgentIssuer[] {
const result: VCLServiceCredentialAgentIssuer[] = [];

try {
const serviceJsonArr = (this.payload[VCLOrganization.KeyService] ??
[]) as JSONObject[];
[]) as Dictionary<any>[];
if (serviceJsonArr) {
for (const i in serviceJsonArr) {
const it = serviceJsonArr[i];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLServiceTypes from "./VCLServiceTypes";

export default class VCLOrganizationsSearchDescriptor {
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/src/api/entities/VCLPlace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Dictionary } from "../VCLTypes";

export default class VCLPlace {
constructor(
public readonly payload: JSONObject,
public readonly payload: Dictionary<any>,
public readonly code: string,
public readonly name: string
) {}
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/api/entities/VCLPresentationRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLDeepLink from "./VCLDeepLink";
import VCLJwt from "./VCLJwt";
import VCLPushDelegate from "./VCLPushDelegate";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLDeepLink from "./VCLDeepLink";
import VCLPushDelegate from "./VCLPushDelegate";

Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/src/api/entities/VCLPublicJwk.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Dictionary } from "../VCLTypes";

enum Format {
jwk = "jwk",
hex = "hex",
Expand All @@ -6,7 +8,7 @@ enum Format {
}

export default class VCLPublicJwk {
constructor(public valueStr: string, public valueJson: JSONObject) {}
constructor(public valueStr: string, public valueJson: Dictionary<any>) {}
static readonly Format = Format;
get curve(): string {
return this.valueJson["crv"];
Expand All @@ -16,7 +18,7 @@ export default class VCLPublicJwk {
return new VCLPublicJwk(valueStr, JSON.parse(valueStr));
}

public static fromJSON(valueJson: JSONObject) {
public static fromJSON(valueJson: Dictionary<any>) {
return new VCLPublicJwk(JSON.stringify(valueJson), valueJson);
}
}
4 changes: 3 additions & 1 deletion packages/sdk/src/api/entities/VCLPushDelegate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Dictionary } from "../VCLTypes";

export default class VCLPushDelegate {
constructor(
public readonly pushUrl: string,
Expand All @@ -7,7 +9,7 @@ export default class VCLPushDelegate {
static readonly KeyPushUrl = "pushUrl";
static readonly KeyPushToken = "pushToken";

toJsonObject() {
toJsonObject(): Dictionary<any> {
return {
[VCLPushDelegate.KeyPushUrl]: this.pushUrl,
[VCLPushDelegate.KeyPushToken]: this.pushToken,
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/api/entities/VCLRegion.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Dictionary } from "../VCLTypes";
import VCLPlace from "./VCLPlace";

export default class VCLRegion extends VCLPlace {
constructor(payload: JSONObject, code: string, name: string) {
constructor(payload: Dictionary<any>, code: string, name: string) {
super(payload, code, name);
}

Expand Down
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 { Nullish } from "../../types";
import { Nullish } from "../VCLTypes";
import VCLError from "./error/VCLError";

export default class VCLResult<R> {
Expand Down
Loading

0 comments on commit 1ebc0d4

Please sign in to comment.