Skip to content

Commit

Permalink
chore: add extended verification to rpc (#623)
Browse files Browse the repository at this point in the history
Co-authored-by: martines3000 <domajnko.martin@gmail.com>
  • Loading branch information
tadejpodrekar and martines3000 authored Apr 22, 2024
1 parent 4914969 commit 34fef30
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-icons-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/masca": patch
---

Use external verification for verifyData rpc.
1 change: 1 addition & 0 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"dependencies": {
"@0xpolygonid/js-sdk": "1.9.4",
"@blockchain-lab-um/did-provider-key": "1.0.8",
"@blockchain-lab-um/extended-verification": "0.1.2",
"@blockchain-lab-um/masca-types": "1.3.2",
"@blockchain-lab-um/oidc-client-plugin": "0.3.1",
"@blockchain-lab-um/oidc-types": "0.0.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"./files/circuits/credentialAtomicQuerySigV2/circuit_final.zkey",
"./files/circuits/credentialAtomicQuerySigV2/verification_key.json"
],
"shasum": "p2I0ddoVhfR/VsWnSWjrs45ADC2xc5Tyl1lOA84R2bI="
"shasum": "lOw1jx4zXBYIWfueSGAiWQzu9ZfZrIbEg8EjNMZuG5o="
},
"initialPermissions": {
"endowment:ethereum-provider": {},
Expand Down
1 change: 0 additions & 1 deletion packages/snap/src/Snap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ class SnapService {

const res = await VeramoService.verifyData(params);

if (res.error) throw new Error(res.error.message);
return verbose ? res : res.verified;
}

Expand Down
39 changes: 19 additions & 20 deletions packages/snap/src/veramo/Veramo.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
type VerificationResult,
VerificationService,
} from '@blockchain-lab-um/extended-verification';
import {
KeyDIDProvider,
getDidKeyResolver as keyDidResolver,
Expand Down Expand Up @@ -111,6 +115,7 @@ class VeramoService {

static async init(): Promise<void> {
VeramoService.instance = await VeramoService.createAgent();
await VerificationService.init();
}

/**
Expand Down Expand Up @@ -516,28 +521,22 @@ class VeramoService {
static async verifyData(
params: VerifyDataRequestParams
): Promise<IVerifyResult> {
try {
const { credential, presentation } = params;
const { credential, presentation } = params;

if (credential) {
const vcResult = await VeramoService.instance.verifyCredential({
credential,
});
return JSON.parse(JSON.stringify(vcResult)) as IVerifyResult;
}
if (presentation) {
const vpResult = await VeramoService.instance.verifyPresentation({
presentation,
});
return JSON.parse(JSON.stringify(vpResult)) as IVerifyResult;
}
return {
verified: false,
error: new Error('No valid credential or presentation.'),
} as IVerifyResult;
} catch (error: unknown) {
return { verified: false, error: error as Error } as IVerifyResult;
let result: Result<VerificationResult> | undefined = undefined;
if (credential) {
result = await VerificationService.verify(credential);
} else if (presentation) {
result = await VerificationService.verify(presentation);
}

if (!result) throw new Error('No valid credential or presentation.');

if (isError(result)) {
throw new Error(result.error);
}

return result.data as IVerifyResult;
}

static async handleOIDCCredentialOffer(params: {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34fef30

Please sign in to comment.