Skip to content

Commit

Permalink
Merge pull request #91 from JustaName-id/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Ghadi8 authored Jan 3, 2025
2 parents 86acd33 + 05764fe commit f74b5a7
Show file tree
Hide file tree
Showing 49 changed files with 21,130 additions and 20,134 deletions.
3 changes: 3 additions & 0 deletions apps/openpassport-static/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_APP_API_DOMAIN=<your-vc-api-domain>/verifications/v1
VITE_APP_ENVIRONMENT=<YOUR_ENVIRONMENT># (development, production, staging, test)
VITE_APP_OPENPASSPORT_SCOPE=<YOUR_OPENPASSPORT_SCOPE>
18 changes: 18 additions & 0 deletions apps/openpassport-static/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
1 change: 1 addition & 0 deletions apps/openpassport-static/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
15 changes: 15 additions & 0 deletions apps/openpassport-static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>OpenpassportStatic</title>
<base href="/" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions apps/openpassport-static/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'openpassport-static',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/openpassport-static',
};
9 changes: 9 additions & 0 deletions apps/openpassport-static/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "openpassport-static",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/openpassport-static/src",
"projectType": "application",
"tags": [],
"// targets": "to see all targets run: nx show project openpassport-static --web",
"targets": {}
}
Binary file added apps/openpassport-static/public/favicon.ico
Binary file not shown.
52 changes: 52 additions & 0 deletions apps/openpassport-static/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import axios from 'axios';
import { OpenPassportQRcode } from '@openpassport/qrcode';
import { OpenPassportAttestation, OpenPassportVerifier } from '@openpassport/core';

export function App() {
const address = new URLSearchParams(window.location.search).get('address');
const state = new URLSearchParams(window.location.search).get('state');

const environment = import.meta.env.VITE_APP_ENVIRONMENT;
const scope = import.meta.env.VITE_APP_OPENPASSPORT_SCOPE;
let openPassportVerifier = new OpenPassportVerifier('prove_offchain', scope);

if (environment === 'development' || environment === 'staging') {
openPassportVerifier = openPassportVerifier.allowMockPassports();
}

const callback = async (attestation: OpenPassportAttestation) => {
try {
const encodedAttestation = btoa(JSON.stringify(attestation));

await axios.get(
`${import.meta.env.VITE_APP_API_DOMAIN}/credentials/socials/openpassport/callback`,
{
params: {
code: encodedAttestation,
state: state,
},
}
);
} catch (error) {
console.error('Error in callback:', error);
}
}

if (!address || !state) {
return <h2>Please provide an address parameter in the URL to continue</h2>;
}

return (
<OpenPassportQRcode
appName={scope}
userId={address.replace("0x", "")}
userIdType={"hex"}
openPassportVerifier={openPassportVerifier}
onSuccess={async (attestation) => {
await callback(attestation);
}}
/>
);
}

export default App;
Empty file.
16 changes: 16 additions & 0 deletions apps/openpassport-static/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Buffer } from 'buffer';
import { StrictMode } from 'react';
import * as ReactDOM from 'react-dom/client';

import App from './app/app';

window.Buffer = Buffer;

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
<StrictMode>
<App />
</StrictMode>
);
23 changes: 23 additions & 0 deletions apps/openpassport-static/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts",
"vite/client"
]
},
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.jsx",
"src/**/*.test.jsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
}
21 changes: 21 additions & 0 deletions apps/openpassport-static/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"types": ["vite/client"]
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json"
}
25 changes: 25 additions & 0 deletions apps/openpassport-static/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": [
"jest",
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
40 changes: 40 additions & 0 deletions apps/openpassport-static/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/// <reference types='vitest' />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';

export default defineConfig({
root: __dirname,
cacheDir: '../../node_modules/.vite/apps/openpassport-static',

define: {
'global': {},
},

server: {
port: 4200,
host: 'localhost',
},

preview: {
port: 4300,
host: 'localhost',
},

plugins: [react(), nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },

build: {
outDir: '../../dist/apps/openpassport-static',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
},
},
});
3 changes: 3 additions & 0 deletions apps/vc-api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ TELEGRAM_BOT_TOKEN=<YOUR_TELEGRAM_BOT_TOKEN>
TELEGRAM_BOT_USERNAME=<YOUR_TELEGRAM_BOT_USERNAME>
TELEGRAM_STATIC_PAGE_URL=<YOUR_TELEGRAM_STATIC_PAGE_URL>

OPENPASSPORT_SCOPE=<YOUR_OPENPASSPORT_SCOPE>
OPENPASSPORT_STATIC_PAGE_URL=<YOUR_OPENPASSPORT_STATIC_PAGE_URL>

DISCORD_CLIENT_ID=<YOUR_DISCORD_CLIENT_ID>
DISCORD_CLIENT_SECRET=<YOUR_DISCORD_CLIENT_SECRET>

Expand Down
4 changes: 3 additions & 1 deletion apps/vc-api/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": ["error"]
"@nx/dependency-checks": ["error", {"ignoredDependencies": [
"@nx/webpack"
]}]
}
}
]
Expand Down
9 changes: 6 additions & 3 deletions apps/vc-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"node": ">=18.12.0 <=18.18.0"
},
"dependencies": {
"@nx/webpack": "19.7.2",
"@veramo/core": "^6.0.0",
"@veramo/credential-eip712": "^6.0.0",
"class-transformer": "^0.5.1",
Expand All @@ -31,7 +30,7 @@
"@golevelup/ts-jest": "^0.5.6",
"supertest": "^7.0.0",
"@nestjs/common": "^10.0.2",
"express": "4.21.1",
"express": "4.21.2",
"@nestjs/core": "^10.0.2",
"ethers": "^6.13.2",
"@nestjs/axios": "^3.0.3",
Expand All @@ -41,6 +40,10 @@
"viem": "^2.21.7",
"@nestjs/platform-express": "^10.0.2",
"@nestjs/testing": "^10.0.2",
"@justaname.id/sdk": "^0.2.146"
"@justaname.id/sdk": "^0.2.146",
"@openpassport/core": "^0.0.11"
},
"devDependencies": {
"@nx/webpack": "19.7.2"
}
}
9 changes: 4 additions & 5 deletions apps/vc-api/src/api/credentials/credentials.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { filter, Subject, take } from 'rxjs';
import { SubjectData } from './isubject.data';
import { JwtGuard } from '../../guards/jwt.guard';
import {CredentialsGenerateEmailOtpApiRequestQuery} from "./requests/credentials.generate-email-otp.request.api";
import {CredentialsGetAuthUrlRequestApiRequestParam} from "./requests/credentials.get-auth-url.request.api";
import {CredentialsGetAuthUrlApiRequestQuery, CredentialsGetAuthUrlRequestApiRequestParam} from "./requests/credentials.get-auth-url.request.api";
import {CredentialsGenerateEmailResponseApi} from "./responses/credentials.generate.email.response.api";
import {CredentialsResendOtpRequestApi} from "./requests/credentials.resend-otp.request.api";
import {CredentialsVerifyOtpRequestApi} from "./requests/credentials.verify-otp.request.api";
Expand Down Expand Up @@ -40,15 +40,14 @@ export class CredentialsController {
@Res() res: Response,
@Req() req: Request & { user: Siwens }
): Promise<any> {

const authId = uuidv4();
const subject = new Subject<SubjectData>();
this.authSubjects.set(authId, subject);

const redirectUrl = await this.credentialCreatorFacade.getSocialAuthUrl(
authGetAuthUrlRequestApi.authName,
req.user?.ens,
req.user?.chainId,
req.user.ens,
req.user.chainId,
authId
)

Expand Down Expand Up @@ -81,7 +80,7 @@ export class CredentialsController {
@Get('socials/:authName/callback')
async callback(
@Param() authGetAuthUrlRequestApiParam: CredentialsGetAuthUrlRequestApiRequestParam,
@Query() authGetAuthUrlRequestApiQuery: any,
@Query() authGetAuthUrlRequestApiQuery: CredentialsGetAuthUrlApiRequestQuery,
@Res() res: Response
): Promise<void> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum AuthName {
Github = 'github',
Discord = 'discord',
Telegram = 'telegram',
OpenPassport = 'openpassport',
}

export class CredentialsGetAuthUrlRequestApiRequestParam
Expand Down
2 changes: 2 additions & 0 deletions apps/vc-api/src/api/filters/vc.api.filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AuthenticationExceptionFilter } from './auth/authentication.filter';
import { JustaNameInitializerExceptionFilter } from './auth/justaName-intializer.filter';
import { Web3ProviderExceptionFilter } from './web3-provider/web3-provider.filter';
import { RecordsFetchingExceptionFilter } from './verify-records/records-fetching.filter';
import { VerificationFailedExceptionFilter } from './verify-records/verification-failed.filter';

export const VCManagementApiFilters = [
OTPExceptionFilter,
Expand All @@ -18,4 +19,5 @@ export const VCManagementApiFilters = [
SocialResolverNotFoundExceptionFilter,
Web3ProviderExceptionFilter,
RecordsFetchingExceptionFilter,
VerificationFailedExceptionFilter,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BaseExceptionFilter } from '@nestjs/core';
import { ArgumentsHost, Catch, HttpStatus } from '@nestjs/common';
import { VerificationFailedException } from '../../../core/domain/exceptions/VerificationFailed.exception';

@Catch(VerificationFailedException)
export class VerificationFailedExceptionFilter extends BaseExceptionFilter {
catch(exception: VerificationFailedException, host: ArgumentsHost) {
const context = host.switchToHttp();
const response = context.getResponse();
const httpStatus = HttpStatus.BAD_REQUEST;

response.status(httpStatus).json({
message: exception.message,
});
}
}
6 changes: 6 additions & 0 deletions apps/vc-api/src/config/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class EnvironmentVariables implements Environment{
@IsString({message: 'TELEGRAM_STATIC_PAGE_URL must be a string'})
TELEGRAM_STATIC_PAGE_URL!: string;

@IsString({message: 'OPENPASSPORT_STATIC_PAGE_URL must be a string'})
OPENPASSPORT_STATIC_PAGE_URL!: string;

@IsString({message: 'OPENPASSPORT_SCOPE must be a string'})
OPENPASSPORT_SCOPE!: string;

@IsString({message: 'JWT_SECRET must be a string'})
JWT_SECRET: string;

Expand Down
Loading

0 comments on commit f74b5a7

Please sign in to comment.