Skip to content

Commit

Permalink
Fixed hot replacement + various enhancements on feature toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
Eengineer1 committed Aug 29, 2023
1 parent d09bba8 commit 02086e1
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 67 deletions.
186 changes: 145 additions & 41 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@
"package.json",
"README.md"
],
"optionalDependencies": {
"@verida/account-node": "^2.3.7",
"@verida/client-ts": "^2.3.7",
"@verida/types": "^2.3.1",
"@verida/vda-did-resolver": "^2.3.7"
},
"dependencies": {
"@cheqd/did-provider-cheqd": "^3.6.6",
"@cheqd/sdk": "^3.6.1",
"@cheqd/ts-proto": "^3.3.1",
"@cosmjs/amino": "^0.31.1",
"@cosmjs/encoding": "^0.31.1",
"@logto/express": "^2.1.0",
"@types/jsonwebtoken": "^9.0.2",
"@veramo/core": "^5.4.1",
"@veramo/credential-ld": "^5.4.1",
"@veramo/credential-w3c": "^5.4.1",
Expand All @@ -61,10 +66,6 @@
"@veramo/did-resolver": "^5.4.1",
"@veramo/key-manager": "^5.4.1",
"@veramo/kms-local": "^5.4.1",
"@verida/account-node": "^2.3.7",
"@verida/client-ts": "^2.3.7",
"@verida/types": "^2.3.1",
"@verida/vda-did-resolver": "^2.3.7",
"cookie-parser": "^1.4.6",
"copyfiles": "^2.4.1",
"cors": "^2.8.5",
Expand Down Expand Up @@ -100,6 +101,7 @@
"@types/express-session": "^1.17.7",
"@types/helmet": "^4.0.0",
"@types/json-stringify-safe": "^5.0.0",
"@types/jsonwebtoken": "^9.0.2",
"@types/node": "^20.5.6",
"@types/secp256k1": "^4.0.3",
"@types/swagger-jsdoc": "^6.0.1",
Expand Down
18 changes: 9 additions & 9 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { RevocationController } from './controllers/revocation.js';
import { CORS_ALLOWED_ORIGINS, CORS_ERROR_MSG, configLogToExpress } from './types/constants.js';
import { LogToWebHook } from './middleware/hook.js';
import { Middleware } from './middleware/middleware.js';
// import { JSONStringify } from './monkey-patch.js';
import { JSONStringify } from './monkey-patch.js';

import * as dotenv from 'dotenv';
dotenv.config();
Expand All @@ -28,14 +28,14 @@ dotenv.config();
// TODO: with JSON.sortify = require('json.sortify')
// see: https://github.com/verida/verida-js/blob/c94b95de687c64cc776652602665bb45a327dfb6/packages/encryption-utils/src/index.ts#L10
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// JSON.stringify = function (value, _replacer, _space) {
// return (
// JSONStringify(value) ||
// (function () {
// throw new Error('JSON.stringify failed');
// })()
// );
// };
JSON.stringify = function (value, _replacer, _space) {
return (
JSONStringify(value) ||
(function () {
throw new Error('JSON.stringify failed');
})()
);
};

// Define Swagger file
import swaggerDocument from './static/swagger.json' assert { type: 'json' };
Expand Down
11 changes: 11 additions & 0 deletions src/controllers/revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,17 @@ export class RevocationController {
}`,
} satisfies CheckStatusListUnsuccessfulResponseBody);

// handle incorrect access control conditions
if (errorRef?.errorCode === 'incorrect_access_control_conditions')
return response.status(StatusCodes.BAD_REQUEST).json({
checked: false,
error: `check: error: ${
errorRef?.message
? 'incorrect access control conditions'
: (error as Record<string, unknown>).toString()
}`,
} satisfies CheckStatusListUnsuccessfulResponseBody);

// return catch-all error
return response.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
checked: false,
Expand Down
6 changes: 5 additions & 1 deletion src/monkey-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export const JSONStringify = (obj: Record<string, any> | null) => {
return tempArr.join('');
};

const escape = (str: string) => {
return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
};

if (ignoreDataTypes(obj)) {
return undefined;
}
Expand All @@ -88,7 +92,7 @@ export const JSONStringify = (obj: Record<string, any> | null) => {

if (restOfDataTypes(obj)) {
const passQuotes = isString(obj) ? `"` : '';
return `${passQuotes}${obj}${passQuotes}`;
return `${passQuotes}${isString(obj) ? escape(obj as unknown as string) : obj }${passQuotes}`;
}

if (isArray(obj)) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/connectors/verida.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class VeridaService {
)
}

const messagingClient = await this.context!.getMessaging()
const messagingClient = await this.context?.getMessaging()

const messageType = 'inbox/type/dataSend' // There are different types of message, here we are sending some data.
const messageData = {
Expand All @@ -93,7 +93,7 @@ export class VeridaService {
did: recipientDid,
}

await messagingClient.send(
await messagingClient?.send(
recipientDid,
messageType,
messageData,
Expand Down
5 changes: 4 additions & 1 deletion src/services/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { CredentialPayload, VerifiableCredential } from '@veramo/core';
import { VC_CONTEXT, VC_TYPE } from '../types/constants.js';
import type { CredentialRequest } from '../types/shared.js';
import { IdentityServiceStrategySetup } from './identity/index.js';
import { VeridaService } from '../services/connectors/verida.js';
import { v4 } from 'uuid';
import * as dotenv from 'dotenv';
dotenv.config();
Expand Down Expand Up @@ -41,6 +40,10 @@ export class Credentials {

if (ENABLE_VERIDA_CONNECTOR === 'true' && request.subjectDid.startsWith('did:vda')) {
if (!request.credentialSchema) throw new Error('Credential schema is required');

// dynamic import to avoid circular dependency
const { VeridaService } = await import('./connectors/verida.js');

await VeridaService.instance.sendCredential(
request.subjectDid,
'New Verifiable Credential',
Expand Down
29 changes: 21 additions & 8 deletions src/services/identity/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { KeyManager } from '@veramo/key-manager';
import { DIDStore, KeyStore } from '@veramo/data-store';
import { DIDManager } from '@veramo/did-manager';
import { DIDResolverPlugin, getUniversalResolver as UniversalResolver } from '@veramo/did-resolver';
import { getResolver as VeridaResolver } from '@verida/vda-did-resolver';
import { CredentialPlugin } from '@veramo/credential-w3c';
import { CredentialIssuerLD, LdDefaultContexts, VeramoEd25519Signature2018 } from '@veramo/credential-ld';
import {
Expand Down Expand Up @@ -51,7 +50,6 @@ import {
import type { CheqdNetwork } from '@cheqd/sdk';
import { getDidKeyResolver as KeyDidResolver } from '@veramo/did-provider-key';
import { Resolver, ResolverRegistry } from 'did-resolver';

import {
BroadcastStatusListOptions,
CheckStatusListOptions,
Expand All @@ -74,6 +72,11 @@ import {
import { MINIMAL_DENOM, VC_PROOF_FORMAT, VC_REMOVE_ORIGINAL_FIELDS } from '../../types/constants.js';
import { toCoin, toDefaultDkg, toMinimalDenom } from '../../helpers/helpers.js';

// dynamic import to avoid circular dependency
const VeridaResolver = process.env.ENABLE_VERIDA_CONNECTOR === 'true'
? (await import('@verida/vda-did-resolver')).getResolver
: undefined;

export class Veramo {
static instance = new Veramo();

Expand Down Expand Up @@ -115,14 +118,24 @@ export class Veramo {
}

if (enableResolver) {
// construct resolver map
const resolvers = {
...(CheqdDidResolver({ url: process.env.RESOLVER_URL }) as ResolverRegistry),
...KeyDidResolver(),
...UniversalResolver(),
}

// handle optional dependencies
if (VeridaResolver) {
const veridaResolver = VeridaResolver();

// add verida resolver to resolver map
Object.assign(resolvers, veridaResolver);
}

plugins.push(
new DIDResolverPlugin({
resolver: new Resolver({
...(CheqdDidResolver({ url: process.env.RESOLVER_URL }) as ResolverRegistry),
...KeyDidResolver(),
...VeridaResolver(),
...UniversalResolver(),
}),
resolver: new Resolver(resolvers),
})
);
}
Expand Down

0 comments on commit 02086e1

Please sign in to comment.