Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix did:vda validator #512

Merged
merged 8 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ jobs:
LOGTO_WEBHOOK_SECRET: ${{ secrets.LOGTO_WEBHOOK_SECRET }}
MAINNET_RPC_URL: ${{ vars.MAINNET_RPC_URL }}
POLYGON_PRIVATE_KEY: ${{ secrets.POLYGON_PRIVATE_KEY }}
POLYGON_RPC_URL: ${{ vars.POLYGON_RPC_URL }}
POLYGON_RPC_URL_MAINNET: ${{ vars.POLYGON_RPC_URL_MAINNET }}
POLYGON_RPC_URL_TESTNET: ${{ vars.POLYGON_RPC_URL_TESTNET }}
POLYGON_RPC_URL_DEVNET: ${{ vars.POLYGON_RPC_URL_DEVNET }}
POLYGON_RPC_URL_LOCAL: ${{ vars.POLYGON_RPC_URL_LOCAL }}
RESOLVER_URL: ${{ vars.RESOLVER_URL }}
TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }}
TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/validator/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class VeridaDIDValidator extends BaseDidValidator implements IValidator {
}

// Check if namespace is valid
if (!(namespace in EnvironmentType)) {
if (!Object.values(EnvironmentType).includes(namespace)) {
return {
valid: false,
error: `Verida DID namespace must be ${EnvironmentType.MAINNET} or ${EnvironmentType.TESTNET}`,
Expand Down
10 changes: 7 additions & 3 deletions src/services/connectors/verida.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class VeridaService {
didClientConfig: {
callType: 'web3',
web3Config: {
rpcUrl: POLYGON_RPC_URL,
rpcUrl: POLYGON_RPC_URL[environment],
privateKey: polygonPrivateKey, // Polygon private key for creating DID, not needed in our case but required in the current version of the config.
},
},
Expand All @@ -61,8 +61,12 @@ export class VeridaService {
},
account: this.account[environment]!,
});

if (this.context[environment] === undefined) {
throw new Error(`Verida client connection failed for environment: ${environment}`);
}
} catch (error) {
throw new Error(`Error: ${error}`);
throw new Error(`${(error as Error).message || error}`);
}
}

Expand All @@ -75,7 +79,7 @@ export class VeridaService {
*/
async sendData(environment: EnvironmentType, recipientDid: string, subject: string, data: DataRecord) {
try {
if (!this.context) {
if (!this.context[environment]) {
await VeridaService.instance.init(
environment,
VERIDA_APP_NAME,
Expand Down
8 changes: 7 additions & 1 deletion src/types/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { EnvironmentType } from '@verida/types';
import * as dotenv from 'dotenv';
dotenv.config();

Expand Down Expand Up @@ -62,7 +63,12 @@ export const VC_REMOVE_ORIGINAL_FIELDS = true;
export const CORS_ERROR_MSG = 'The CORS policy for this site does not allow access from the specified Origin.';

// Verida
export const POLYGON_RPC_URL = process.env.POLYGON_RPC_URL || 'https://rpc.ankr.com/polygon_mumbai';
export const POLYGON_RPC_URL: Record<EnvironmentType, string> = {
mainnet: process.env.POLYGON_RPC_URL_MAINNET || 'https://polygon-rpc.com',
testnet: process.env.POLYGON_RPC_URL_TESTNET || 'https://rpc.ankr.com/polygon_mumbai',
devnet: process.env.POLYGON_RPC_URL_DEVNET,
local: process.env.POLYGON_RPC_URL_LOCAL,
};
export const VERIDA_APP_NAME = 'Cheqd Verida Connector';
// Schema to store a Verifiable Credential on the Verida Network.
export const VERIDA_CREDENTIAL_RECORD_SCHEMA = 'https://common.schemas.verida.io/credential/base/v0.2.0/schema.json';
Expand Down
5 changes: 4 additions & 1 deletion src/types/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ declare global {

// Verida
ENABLE_VERIDA_CONNECTOR: string | 'false';
POLYGON_RPC_URL: string;
POLYGON_RPC_URL_MAINNET: string;
POLYGON_RPC_URL_TESTNET: string;
POLYGON_RPC_URL_DEVNET: string;
POLYGON_RPC_URL_LOCAL: string;
VERIDA_PRIVATE_KEY: string;
POLYGON_PRIVATE_KEY: string;

Expand Down
Loading