Commit ab1d70ef authored by Hidde-Jan Jongsma's avatar Hidde-Jan Jongsma

Implement jolocom issueing and verifying

parent 9f03060b
......@@ -1601,6 +1601,15 @@
"integrity": "sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ==",
"dev": true
},
"@types/qrcode": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/@types/qrcode/-/qrcode-1.3.4.tgz",
"integrity": "sha512-aILE5yvKaqQXlY0YPMEYwK/KwdD43fwQTyagj0ffBBTQj8h//085Zp8LUrOnZ9FT69x64f5UgDo0EueY4BPAdg==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/qs": {
"version": "6.9.2",
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.2.tgz",
......
......@@ -6,9 +6,11 @@ import { AppService } from './app.service';
import { IssueModule } from './issue/issue.module';
import { VerifyModule } from './verify/verify.module';
import { UtilsModule } from './utils/utils.module';
import { ConfigModule } from './config/config.module';
@Module({
imports: [
ConfigModule,
TypeOrmModule.forRoot({
type: 'sqlite',
database: '/data/dev.sqlite3',
......
import { Module, Global } from '@nestjs/common';
import { ConfigService } from './config.service';
@Global()
@Module({
providers: [ConfigService],
exports: [ConfigService],
})
export class ConfigModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigService } from './config.service';
describe('ConfigService', () => {
let service: ConfigService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ConfigService],
}).compile();
service = module.get<ConfigService>(ConfigService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
@Injectable()
export class ConfigService {
getServerBaseUrl(): string {
return process.env.SSI_SERVER_URL || 'http://localhost:3000';
}
getIrmaUrl(): string {
return process.env.IRMA_SERVER_URL || 'http://localhost:8989';
}
getUrl(path: string): string {
return new URL(path, this.getServerBaseUrl()).toString();
}
}
......@@ -46,12 +46,4 @@ export interface ConnectorService {
* @returns All data needed for the front-end to set up a verifying session.
*/
handleVerifyCredentialRequest(request: CredentialVerifyRequest): Promise<any>;
// registerRoutes(root: string, app: Express): void;
// processCredentialIssueRequest(request: CredentialIssueRequest): Promise<void>;
// processCredentialVerifyRequest(
// request: CredentialVerifyRequest,
// ): Promise<void>;
}
......@@ -142,7 +142,7 @@ export class IrmaService implements ConnectorService {
};
}
validateIrmaDisclosure(verifyRequest: CredentialVerifyRequest, jwt: string) {
handleIrmaDisclosure(verifyRequest: CredentialVerifyRequest, jwt: string) {
const publicKey = IRMASERVER_PUBLIC_KEY;
const decoded = verify(jwt, publicKey, {
......
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
Index,
} from 'typeorm';
import { CredentialVerifyRequest } from 'src/requests/credential-verify-request.entity';
@Entity()
@Index(['nonce', 'verifyRequest'], { unique: true })
export class JolocomCredentialRequestToken {
@PrimaryGeneratedColumn()
id: number;
@Column()
nonce: string;
@Column({ type: 'text' })
token: string;
@ManyToOne(
() => CredentialVerifyRequest,
vr => vr.jolocomTokens,
)
verifyRequest: CredentialVerifyRequest;
}
import {
BaseEntity,
Entity,
PrimaryGeneratedColumn,
Column,
OneToMany,
} from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { BaseMetadata } from 'cred-types-jolocom-core/js/types';
import { CredentialType } from 'src/types/credential-type.entity';
import {
CredentialRenderTypes,
CredentialOfferRenderInfo,
CredentialOfferMetadata,
} from 'jolocom-lib/js/interactionTokens/interactionTokens.types';
@Entity()
export class JolocomCredentialType extends BaseEntity {
export class JolocomCredentialType {
@PrimaryGeneratedColumn()
id: number;
......@@ -30,4 +29,33 @@ export class JolocomCredentialType extends BaseEntity {
type => type.organization,
)
credentialTypes: CredentialType[];
get schema(): BaseMetadata {
return {
type: ['Credential', this.type],
name: this.name,
context: this.context,
claimInterface: this.claimInterface,
};
}
get offerMetadata(): {
renderInfo?: CredentialOfferRenderInfo;
metadata?: CredentialOfferMetadata;
} {
return {
renderInfo: {
background: {
color: '#ffffff',
},
text: {
color: '#000000',
},
renderAs: CredentialRenderTypes.document,
},
metadata: {
asynchronous: false,
},
};
}
}
import {
BaseEntity,
Entity,
PrimaryGeneratedColumn,
Column,
......@@ -14,7 +13,7 @@ const JOLOCOM_WALLET_SEED_BYTES = 32;
const JOLOCOM_WALLET_PASSWORD_BYTES = 16;
@Entity()
export class JolocomWallet extends BaseEntity {
export class JolocomWallet {
@PrimaryGeneratedColumn()
id: number;
......
......@@ -5,9 +5,16 @@ import { JolocomService } from './jolocom.service';
import { JolocomWallet } from './jolocom-wallet.entity';
import { JolocomCredentialType } from './jolocom-credential-type.entity';
import { JolocomController } from './jolocom.controller';
import { JolocomCredentialRequestToken } from './jolocom-credential-request-token.entity';
@Module({
imports: [TypeOrmModule.forFeature([JolocomWallet, JolocomCredentialType])],
imports: [
TypeOrmModule.forFeature([
JolocomWallet,
JolocomCredentialType,
JolocomCredentialRequestToken,
]),
],
providers: [JolocomService],
exports: [JolocomService, TypeOrmModule],
controllers: [JolocomController],
......
This diff is collapsed.
......@@ -32,6 +32,9 @@ export class Organization {
@OneToOne(
() => JolocomWallet,
wallet => wallet.organization,
{
eager: true,
},
)
jolocomWallet: JolocomWallet;
......
......@@ -4,10 +4,12 @@ import {
Column,
Generated,
ManyToOne,
OneToMany,
} from 'typeorm';
import { CredentialRequest } from './credential-request.interface';
import { Organization } from '../organizations/organization.entity';
import { CredentialType } from 'src/types/credential-type.entity';
import { JolocomCredentialRequestToken } from 'src/connectors/jolocom/jolocom-credential-request-token.entity';
export interface CredentialVerifyRequestData {
jti: string;
......@@ -52,6 +54,12 @@ export class CredentialVerifyRequest implements CredentialRequest {
)
requestor: Organization;
@OneToMany(
() => JolocomCredentialRequestToken,
token => token.verifyRequest,
)
jolocomTokens: JolocomCredentialRequestToken[];
static requestType: string;
get requestId() {
......
......@@ -11,6 +11,7 @@ import {
import { CredentialVerifyRequest } from '../requests/credential-verify-request.entity';
import { RequestsGateway } from '../requests/requests.gateway';
import { IrmaService } from 'src/connectors/irma/irma.service';
import { JolocomService } from 'src/connectors/jolocom/jolocom.service';
import { RequestsService } from 'src/requests/requests.service';
import { ResponseStatus } from 'src/connectors/response-status.enum';
......@@ -20,6 +21,7 @@ export class VerifyController {
private gateway: RequestsGateway,
private connectorsService: ConnectorsService,
private irmaService: IrmaService,
private jolocomService: JolocomService,
private requestsService: RequestsService,
) {
console.log(this.gateway);
......@@ -57,7 +59,7 @@ export class VerifyController {
) {
try {
// TODO: Abstract this properly (also for jolocom)
const result = this.irmaService.validateIrmaDisclosure(
const result = this.irmaService.handleIrmaDisclosure(
verifyRequest,
irmaJwt,
);
......@@ -78,4 +80,35 @@ export class VerifyController {
// TODO: handle bad flow
}
}
@Post('jolocom/disclose')
handleJolocomVerifyDisclosure(
@Query('verifyRequestId', GetVerifyRequestPipe)
verifyRequest: CredentialVerifyRequest,
@Body('token')
jolocomJwt: string,
) {
try {
// TODO: Abstract this properly (also for jolocom)
const result = this.jolocomService.handleJolocomDisclosure(
verifyRequest,
jolocomJwt,
);
const responseToken = this.requestsService.encodeVerifyRequestResponse(
verifyRequest,
ResponseStatus.success,
'jolocom',
result,
);
this.gateway.sendRedirectResponse(
verifyRequest.requestId,
ResponseStatus.success,
`${verifyRequest.callbackUrl}${responseToken}`,
);
} catch {
// TODO: handle bad flow
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment