Skip to content

Commit

Permalink
fix: remove .gitmodules, make did method dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
techsavvyash committed Jun 21, 2023
1 parent 7cd8731 commit 6af1cd1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 143 deletions.
9 changes: 0 additions & 9 deletions .gitmodules

This file was deleted.

125 changes: 4 additions & 121 deletions services/identity-service/src/did/did.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import * as ION from '@decentralized-identity/ion-tools';
import { PrismaService } from 'src/prisma.service';
import { Identity, Prisma } from '@prisma/client';
import { DIDDocument } from 'did-resolver';
import { domainToASCII } from 'url';
import { uuid } from 'uuidv4';
import { GenerateDidDTO } from './dtos/GenerateDid.dto';
import { VaultService } from './vault.service';
Expand All @@ -15,10 +13,9 @@ export class DidService {
async generateDID(doc: GenerateDidDTO): Promise<DIDDocument> {
// Create private/public key pair
const authnKeys = await ION.generateKeyPair('Ed25519');
console.log(authnKeys);

// Create a UUID for the DID using uuidv4
const didUri = 'did:ulp:' + uuid();
const didUri = `did:${doc.method}:${uuid()}`;

// Create a DID Document
const document: DIDDocument = {
Expand All @@ -36,139 +33,25 @@ export class DidService {
],
authentication: ['auth-key'],
};
// print the document using pretty json
console.log(JSON.stringify(document, null, 2));

await this.prisma.identity.create({
data: {
id: didUri,
didDoc: JSON.stringify(document),
},
});
this.vault.writePvtKey(authnKeys.privateJwk, didUri)
this.vault.writePvtKey(authnKeys.privateJwk, didUri);
return document;

// const did = new ION.DID({
// content: content,
// });

// const anchorRequestBody = await did.generateRequest();
// const didUri: string = await did.getURI('short');
// const anchorRequest = new ION.AnchorRequest(anchorRequestBody);
// const anchorResponse = await anchorRequest.submit();
// if (anchorResponse) {
// await this.prisma.identity.create({
// data: {
// id: didUri,
// didDoc: anchorResponse as DIDDocument,
// privateKey: authnKeys.privateJwk,
// },
// });

// return anchorResponse;
// } else {
// throw new Error('err');
// }
}

async resolveDID(id: string): Promise<any> {
console.log('did in resolveDID: ', id);
async resolveDID(id: string): Promise<DIDDocument> {
const artifact = await this.prisma.identity.findUnique({
where: { id },
});
console.log('artifact.didDoc: ', artifact.didDoc);
if (artifact) {
return JSON.parse(artifact.didDoc as string) as DIDDocument;
} else {
return null;
}
}

// async resolveDID(id: string): Promise<DIDDocument> {
// // check on the blockchain and update status
// // URI: https://identity.foundation/ion/explorer/?did={DID}
// try {
// // check in db
// const artifact = await this.prisma.identity.findUnique({
// where: { id },
// });

// if (artifact) {
// if (!artifact.blockchainStatus) {
// try {
// const response = await ION.resolve(id);
// console.log(JSON.stringify(response));
// this.prisma.identity.update({
// where: {
// id,
// },
// data: {
// blockchainStatus: true,
// },
// });
// } catch (err) {
// console.log('not updated on blockchain');
// }
// return artifact.didDoc as DIDDocument;
// }
// } else {
// throw new Error('Not Found');
// }
// } catch (err) {
// throw new NotFoundException(`${id} not found`);
// }
// }

// async updateDID(id: string, data: any) {
// let artifact: Identity | null = null;
// try {
// artifact = await this.prisma.identity.findUnique({
// where: {
// id,
// },
// });
// console.log(
// 'artifact: ',
// JSON.parse(artifact.didDoc as string)?.didDocument
// ?.verificationMethod[0].publicKeyJwk,
// );

// const content = data.content;
// content['publicKeys'] = [
// {
// id: 'auth-key',
// type: 'EcdsaSecp256k1VerificationKey2019',
// publicKeyJwk: JSON.parse(artifact.didDoc as string)?.didDocument
// ?.verificationMethod[0].publicKeyJwk,
// purposes: ['authentication'],
// },
// ];

// const did = new ION.DID({
// content: content,
// });

// console.log('did: ', did);

// const updateOperation = await did.generateOperation('update', {
// addServices: content.services,
// });

// console.log('updateOperation: ', updateOperation);
// const updateRequestBody = await did.generateRequest(1, updateOperation);
// const updateRequest = new ION.AnchorRequest(updateRequestBody);
// console.log('updateRequestBody: ', updateRequestBody);

// const updateResponse = await updateRequest.submit();

// console.log('updateResponse: ', updateResponse);

// // if (updateResponse) {
// return 'Successfully Updated';
// } catch (err) {
// throw new Error(err);
// }
// // }
// // throw new Error('Not Registered');
// }
}
14 changes: 10 additions & 4 deletions services/identity-service/src/did/dtos/GenerateDid.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ import { Service } from 'did-resolver';

export class GenerateDidDTO {
@ApiProperty({
description: 'AlsoKnownAs property is a unique combination aadhaar and username.',
description:
'AlsoKnownAs property is a unique combination aadhaar and username.',
type: String,
isArray: true
isArray: true,
})
alsoKnownAs?: string[];

@ApiProperty({
description: 'An array of services that are used, for example a user registration service.',
isArray: true
description:
'An array of services that are used, for example a user registration service.',
isArray: true,
})
service?: Service[];
@ApiProperty({
description: 'The method of DID.',
})
method: string;
}
13 changes: 4 additions & 9 deletions services/identity-service/src/kyc/kyc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export default class KycService {
constructor(
private readonly httpService: HttpService,
private readonly didService: DidService,
) { }
) {}

async triggerKyc(aadhaar: string) {
const userData = {
email: aadhaar,
};
let response: AxiosResponse<any, any>;
let response: AxiosResponse;
try {
response = await lastValueFrom(
this.httpService.post(
Expand Down Expand Up @@ -52,14 +52,11 @@ export default class KycService {
email: aadhaar,
otp: otp,
};
console.log(userData);
const response = await lastValueFrom(
this.httpService.post('http://64.227.185.154:8000/otp/verify/', userData),
);
console.log(response);
if (response.data) {
if (response.data.status == 200) {
console.log('Verified');
const registrationData = {
registration: {
generateAuthenticationToken: true,
Expand All @@ -75,9 +72,8 @@ export default class KycService {
const headers = {
Authorization: process.env.FUSION_API_KEY,
};
console.log(headers);
try {
const fusionResponse = await lastValueFrom(
await lastValueFrom(
this.httpService.post(
'https://auth.konnect.samagra.io/api/user/registration/',
registrationData,
Expand All @@ -88,8 +84,6 @@ export default class KycService {
aadhaar,
username,
);
console.log({ fusionResponse, registrationDid });
// return { fusionResponse, registrationDid };
return registrationDid;
} catch (err) {
return err;
Expand Down Expand Up @@ -118,6 +112,7 @@ export default class KycService {
serviceEndpoint: 'http://auth.konnect.samagra.io',
},
],
method: 'aadhar',
};

try {
Expand Down

0 comments on commit 6af1cd1

Please sign in to comment.