Skip to content

Commit

Permalink
Add idOS verify step
Browse files Browse the repository at this point in the history
  • Loading branch information
luistorres committed May 7, 2024
1 parent 187d760 commit bcecba6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/web-app/app/_server/idos/idos-grantee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { ethers } from 'ethers';
import nacl from 'tweetnacl';
import { decodeBase58, toBeHex } from 'ethers';
import { EthSigner } from '@kwilteam/kwil-js/dist/core/builders';
import { idOS } from '@idos-network/idos-sdk';

const PLAYGROUND_FRACTAL_ISSUER = 'https://vc-issuers.next.fractal.id/idos';

export function implicitAddressFromPublicKey(publicKey: string) {
const key_without_prefix = publicKey.replace(/^ed25519:/, '');
Expand Down Expand Up @@ -162,13 +165,30 @@ export class idOSGrantee {
);
}

async verifyCredential(credential: any) {
if (process.env.NEXT_PUBLIC_ENABLE_TESTNETS === 'true') {
return await idOS.verifiableCredentials.verify(credential, {
allowedIssuers: [PLAYGROUND_FRACTAL_ISSUER],
});
}

return await idOS.verifiableCredentials.verify(credential);
}

async fetchUserCountriesFromSharedPlusCredential(
dataId: string,
): Promise<TUserCountry> {
const credentialString =
await this.getSharedCredentialContentDecrypted(dataId);
const credential = JSON.parse(credentialString);

try {
const isValid = await this.verifyCredential(credential);
console.log('%c==>VALID:', isValid);
} catch (error) {
console.log(error);
}

if (credential?.level !== 'plus')
return {
residentialCountry: undefined,
Expand Down

0 comments on commit bcecba6

Please sign in to comment.