Skip to content

Commit

Permalink
Merge pull request #93 from velocitycareerlabs/VL-7981-proof
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
michaelavoyan authored Jun 4, 2024
2 parents b88ea05 + d8278c9 commit 3ab49b7
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 46 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.9.7"
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "^0.9.8"
},
"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.7",
"version": "0.9.8",
"description": "VNF Wallet SDK Nodejs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
11 changes: 9 additions & 2 deletions packages/sdk/src/api/entities/VCLCredentialManifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nullish } from "../VCLTypes";
import { Dictionary, Nullish } from "../VCLTypes";
import VCLJwt from "./VCLJwt";
import VCLVerifiedProfile from "./VCLVerifiedProfile";
import VCLDeepLink from "./VCLDeepLink";
Expand Down Expand Up @@ -82,9 +82,16 @@ export default class VCLCredentialManifest {
);
}

/*
* translate from kotlin to typescript private fun retrieveAud() =
((jwt.payload?.toJSONObject()
?.getOrDefault(CodingKeys.KeyMetadata, HashMap<String, Any>()) as? Map<*, *> )
?.getOrDefault(CodingKeys.KeyFinalizeOffersUri, "") as? String ?: "")
.substringBefore("/issue/")
* */
private retrieveAud(): string {
const keyMetadata = this.jwt.payload[VCLCredentialManifest.KeyMetadata] ?? {};
const finalizeOffersUri = (keyMetadata as Record<string, any>)[VCLCredentialManifest.KeyFinalizeOffersUri] ?? "";
const finalizeOffersUri = (keyMetadata as Dictionary<any>)[VCLCredentialManifest.KeyFinalizeOffersUri] ?? "";
return finalizeOffersUri.split("/issue/")[0];
}

Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ export default class VCLFinalizeOffersDescriptor {
get remoteCryptoServicesToken() {
return this.credentialManifest.remoteCryptoServicesToken
}
get finalizeOffersUri() {
return this.credentialManifest.finalizeOffersUri;
}
get did() {
return this.credentialManifest.did;
}
get issuerId() {
return this.credentialManifest.issuerId
}
Expand All @@ -31,6 +25,12 @@ export default class VCLFinalizeOffersDescriptor {
get exchangeId() {
return this.credentialManifest.exchangeId
}
get finalizeOffersUri() {
return this.credentialManifest.finalizeOffersUri;
}
get serviceTypes() {
return this.credentialManifest.verifiedProfile.serviceTypes
}

payload: Dictionary<any> = {
[VCLFinalizeOffersDescriptor.KeyExchangeId]: this.exchangeId,
Expand Down
9 changes: 6 additions & 3 deletions packages/sdk/src/api/entities/error/VCLError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ export default class VCLError extends Error {
return result;
}

static fromException(
exception: Error,
static fromError(
error: Error,
statusCode: number | null = null
): VCLError {
if (error instanceof VCLError) {
return error;
}
return new VCLError(
null,
VCLErrorCode.SdkError.toString(),
exception.message,
error.message,
statusCode
);
}
Expand Down
32 changes: 16 additions & 16 deletions packages/sdk/src/impl/VCLImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("getPresentationRequest", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -250,7 +250,7 @@ export class VCLImpl implements VCL {
);
} catch(error: any) {
logError("submit presentation", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -261,7 +261,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("getExchangeProgress", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -274,7 +274,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("getExchangeProgress", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -291,7 +291,7 @@ export class VCLImpl implements VCL {
null
);
logError('', error);
throw error;
throw VCLError.fromError(error);
}
let verifiedProfile: VCLVerifiedProfile;
try {
Expand All @@ -304,7 +304,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError(`failed to find verified profile by did ${did}`, error);
throw error;
throw VCLError.fromError(error);
}
try {
return await this.credentialManifestUseCase.getCredentialManifest(
Expand All @@ -313,7 +313,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("getCredentialManifest", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -332,7 +332,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("submit identification", error);
throw error;
throw VCLError.fromError(error);
}

VCLLog.i(VCLImpl.TAG, "Identification submitted success.");
Expand Down Expand Up @@ -364,7 +364,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("finalizeOffers", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -380,14 +380,14 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("getCredentialTypesUIFormSchema", error);
throw error;
throw VCLError.fromError(error);
}
} else {
const error = new VCLError(
"No countries for getCredentialTypesUIFormSchema"
);
logError("getCredentialTypesUIFormSchema", error);
throw error;
throw VCLError.fromError(error);
}
}

Expand All @@ -400,7 +400,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("getVerifiedProfile", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -417,7 +417,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("verifyJwt", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -436,7 +436,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("generateSignedJwt", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -447,7 +447,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("generateDidJwk", error);
throw error;
throw VCLError.fromError(error);
}
};

Expand All @@ -466,7 +466,7 @@ export class VCLImpl implements VCL {
);
} catch (error: any) {
logError("generateOffers", error);
throw error;
throw VCLError.fromError(error);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export class FinalizeOffersRepositoryImpl implements FinalizeOffersRepository {
const encodedJwtCredArr: Nullish<string[]> = (finalizedOffersResponse.payload as Nullish<string[]>);
if (encodedJwtCredArr) {
return encodedJwtCredArr.map((encodedJwtCred) => VCLJwt.fromEncodedJwt(encodedJwtCred));
} else if (finalizedOffersResponse.payload instanceof Error) {
throw VCLError.fromError(finalizedOffersResponse.payload);
}

throw new VCLError(`Failed to parse: ${finalizedOffersResponse.payload}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class CountriesUseCaseImpl implements CountriesUseCase {
try {
return await this.countriesRepository.getCountries();
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class CredentialTypesUIFormSchemaUseCaseImpl
countries
);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class CredentialTypesUseCaseImpl
try {
return await this.credentialTypes.getCredentialTypes();
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class ExchangeProgressUseCaseImpl implements ExchangeProgressUseC
try {
return await this.exchangeProgressRepository.getExchangeProgress(exchangeDescriptor);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class FinalizeOffersUseCaseImpl implements FinalizeOffersUseCase
)
}
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class GenerateOffersUseCaseImpl
try {
return await this.generateOffersRepository.generateOffers(generateOffersDescriptor, sessionToken);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class JwtServiceUseCaseImpl implements JwtServiceUseCase {
try {
return await this.jwtServiceRepository.verifyJwt(jwt, publicJwk, remoteCryptoServicesToken);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class KeyServiceUseCaseImpl implements KeyServiceUseCase {
try {
return await this.keyServiceRepository.generateDidJwk(didJwkDescriptor);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class OrganizationsUseCaseImpl implements OrganizationsUseCase {
try {
return await this.organizationsRepository.searchForOrganizations(organizationsSearchDescriptor);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class PresentationRequestUseCaseImpl
),
);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class SubmissionUseCaseImpl implements SubmissionUseCase {
);
return await this.submissionRepository.submit(submission, jwt);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class VerifiedProfileUseCaseImpl
try {
return await this.verifiedProfileRepository.getVerifiedProfile(verifiedProfileDescriptor);
} catch (error: any) {
throw new VCLError(error);
throw VCLError.fromError(error);
}
}
}
25 changes: 21 additions & 4 deletions packages/sdk/test/entities/VCLFinalizeOffersDescriptor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ describe("VCLCredentialManifest Tests", () => {

let subject: VCLFinalizeOffersDescriptor;

// const jtiMock = "some jti"
// const issMock = "some iss"
// const audMock = "some sud"
const nonceMock = "some nonce"

const approvedOfferIds = ["approvedOfferId1", "approvedOfferId2"]
const rejectedOfferIds = ["rejectedOfferId1", "rejectedOfferId2"]

const jwtProof = VCLJwt.fromEncodedJwt(
`eyJraWQiOiJkaWQ6andrOmV5SnJkSGtpT2lKRlF5SXNJblZ6WlNJNkluTnBaeUlzSW1OeWRpSTZJbEF0TWpVMklpd2lhMmxrSWpvaVpHSmlNVGd5TXpndE56a3hZaTAwTmpkaUxXRTBZak10T0RjeE0yVTFNVGN3TkRObElpd2llQ0k2SWs1NVkxcEhhMmt5U1ZGRldta3pVRmN0UXkwNVIzRjNRakJsZDNVNWR6QkdXV2xrTTFaVmJGOTJPRFFpTENKNUlqb2liVXhtY1dNMmIyWXhVVFYwVHpZeGQwbDFkVFpQVVZaUmMySjRUR1poT0VkaGMwaFZUR3B3VTJWVmJ5SjkjMCIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2IiwiandrIjp7Imt0eSI6IkVDIiwidXNlIjoic2lnIiwiY3J2IjoiUC0yNTYiLCJraWQiOiJkYmIxODIzOC03OTFiLTQ2N2ItYTRiMy04NzEzZTUxNzA0M2UiLCJ4IjoiTnljWkdraTJJUUVaaTNQVy1DLTlHcXdCMGV3dTl3MEZZaWQzVlVsX3Y4NCIsInkiOiJtTGZxYzZvZjFRNXRPNjF3SXV1Nk9RVlFzYnhMZmE4R2FzSFVManBTZVVvIn19.eyJhdWQiOiJzb21lIHN1ZCIsInN1YiI6IlB2aFNOdWF6MTYiLCJuYmYiOjE3MTc0ODk2NzksImlzcyI6InNvbWUgaXNzIiwiZXhwIjoxNzE4MDk0NDc5LCJpYXQiOjE3MTc0ODk2NzksIm5vbmNlIjoic29tZSBub25jZSIsImp0aSI6InNvbWUganRpIn0.VRacheqy4sWIo3CKPsOJTYJnfyx3KaFYIQykXIS4xpMs58iCCp-pRnsLmoC56eJPCqRkv_A-MCdpc3pgiM3UVA`
)
const expectedRequestBodyStr =
`{"exchangeId":"645e315309237c760ac022b1","approvedOfferIds":["approvedOfferId1","approvedOfferId2"],"rejectedOfferIds":["rejectedOfferId1","rejectedOfferId2"],"proof":{"proof_type":"jwt","jwt":"eyJraWQiOiJkaWQ6andrOmV5SnJkSGtpT2lKRlF5SXNJblZ6WlNJNkluTnBaeUlzSW1OeWRpSTZJbEF0TWpVMklpd2lhMmxrSWpvaVpHSmlNVGd5TXpndE56a3hZaTAwTmpkaUxXRTBZak10T0RjeE0yVTFNVGN3TkRObElpd2llQ0k2SWs1NVkxcEhhMmt5U1ZGRldta3pVRmN0UXkwNVIzRjNRakJsZDNVNWR6QkdXV2xrTTFaVmJGOTJPRFFpTENKNUlqb2liVXhtY1dNMmIyWXhVVFYwVHpZeGQwbDFkVFpQVVZaUmMySjRUR1poT0VkaGMwaFZUR3B3VTJWVmJ5SjkjMCIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2IiwiandrIjp7Imt0eSI6IkVDIiwidXNlIjoic2lnIiwiY3J2IjoiUC0yNTYiLCJraWQiOiJkYmIxODIzOC03OTFiLTQ2N2ItYTRiMy04NzEzZTUxNzA0M2UiLCJ4IjoiTnljWkdraTJJUUVaaTNQVy1DLTlHcXdCMGV3dTl3MEZZaWQzVlVsX3Y4NCIsInkiOiJtTGZxYzZvZjFRNXRPNjF3SXV1Nk9RVlFzYnhMZmE4R2FzSFVManBTZVVvIn19.eyJhdWQiOiJzb21lIHN1ZCIsInN1YiI6IlB2aFNOdWF6MTYiLCJuYmYiOjE3MTc0ODk2NzksImlzcyI6InNvbWUgaXNzIiwiZXhwIjoxNzE4MDk0NDc5LCJpYXQiOjE3MTc0ODk2NzksIm5vbmNlIjoic29tZSBub25jZSIsImp0aSI6InNvbWUganRpIn0.VRacheqy4sWIo3CKPsOJTYJnfyx3KaFYIQykXIS4xpMs58iCCp-pRnsLmoC56eJPCqRkv_A-MCdpc3pgiM3UVA"}}`;

beforeAll(async () => {
const credentialManifest =
new VCLCredentialManifest(
Expand All @@ -36,12 +45,20 @@ describe("VCLCredentialManifest Tests", () => {
)
});

test("test generateRequest body", () => {
const jwtProof = VCLJwt.fromEncodedJwt(
'eyJraWQiOiJkaWQ6andrOmV5SnJkSGtpT2lKRlF5SXNJblZ6WlNJNkluTnBaeUlzSW1OeWRpSTZJbEF0TWpVMklpd2lhMmxrSWpvaU56VXhOekZsWm1FdFkyTTRNaTAwWlRVeUxXSTFaVFl0WkRRMlpXRmhaamMzTkRneElpd2llQ0k2SW0xRldEbHliR2hJWVVaVmNreEtla0p4VWt4bmIySndNVmR4UzJSTmFEVndiVVp5UzJjME9WbEZkVUVpTENKNUlqb2lWakZPTVdKU1FrRXplalp2VGxrelZXdFFORUZsWVVGQk5rNUtiREl5TVRSVWFVSnFTRTlJYWpGdVVTSjkjMCIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2IiwiandrIjp7Imt0eSI6IkVDIiwidXNlIjoic2lnIiwiY3J2IjoiUC0yNTYiLCJraWQiOiI3NTE3MWVmYS1jYzgyLTRlNTItYjVlNi1kNDZlYWFmNzc0ODEiLCJ4IjoibUVYOXJsaEhhRlVyTEp6QnFSTGdvYnAxV3FLZE1oNXBtRnJLZzQ5WUV1QSIsInkiOiJWMU4xYlJCQTN6Nm9OWTNVa1A0QWVhQUE2TkpsMjIxNFRpQmpIT0hqMW5RIn19.eyJrZXkxIjoidmFsdWUxIiwiYXVkIjoic29tZSBzdWQiLCJzdWIiOiJ3VzdCZGhXNGNQIiwibmJmIjoxNzE2OTAzNzIxLCJpc3MiOiJzb21lIGlzcyIsImV4cCI6MTcxNzUwODUyMSwiaWF0IjoxNzE2OTAzNzIxLCJub25jZSI6InNvbWUgbm9uY2UiLCJqdGkiOiJzb21lIGp0aSJ9'
)
test("test props", async () => {
expect(subject.finalizeOffersUri).toBe("https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA/issue/finalize-offers")
expect(subject.approvedOfferIds).toStrictEqual(approvedOfferIds)
expect(subject.rejectedOfferIds).toStrictEqual(rejectedOfferIds)
expect(subject.aud).toBe("https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA")
expect(subject.issuerId).toBe("did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA")

});

test("test generateRequest body", async () => {
const requestBody = subject.generateRequestBody(jwtProof)

expect(requestBody).toStrictEqual(JSON.parse(expectedRequestBodyStr));

expect(requestBody["exchangeId"]).toBe("645e315309237c760ac022b1")
expect(requestBody["approvedOfferIds"]).toStrictEqual(approvedOfferIds)
expect(requestBody["rejectedOfferIds"]).toStrictEqual(rejectedOfferIds)
Expand Down

0 comments on commit 3ab49b7

Please sign in to comment.