From 7ddb7555ec1924d607bca570eb0339227c07917a Mon Sep 17 00:00:00 2001 From: edac99 Date: Tue, 7 May 2024 20:56:59 +0900 Subject: [PATCH] =?UTF-8?q?modify:=20proof=20value=20=EC=A6=89=EC=8B=9C=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=ED=9B=84=20vc=EC=97=90=20=EC=82=BD?= =?UTF-8?q?=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getProofValue 메서드 삭제 및 API 통신 단축 --- BE/holder/src/config/.test.env | 1 - BE/holder/src/holder/holder-api.controller.ts | 31 ++++++++++--------- BE/holder/src/holder/holder-api.service.ts | 20 ++---------- BE/issuer/src/issuer/issuer-api.controller.ts | 5 +-- BE/issuer/src/issuer/issuer-api.service.ts | 10 ++++-- BE/issuer/src/utils/utils.ts | 10 ++++-- 6 files changed, 36 insertions(+), 41 deletions(-) diff --git a/BE/holder/src/config/.test.env b/BE/holder/src/config/.test.env index 351a602..ffe0a4b 100644 --- a/BE/holder/src/config/.test.env +++ b/BE/holder/src/config/.test.env @@ -1,5 +1,4 @@ API_CREATE_USER_VC=http://localhost:8082/api/issuer/create-vc -API_GET_PROOF_VALUE=http://localhost:8082/api/issuer/generate-proof-value MAIL_PASSWORD=pwdpwd MAIL_USER=noreply@gmail.com JWT_SECRET=secrete diff --git a/BE/holder/src/holder/holder-api.controller.ts b/BE/holder/src/holder/holder-api.controller.ts index 5af010e..f330714 100644 --- a/BE/holder/src/holder/holder-api.controller.ts +++ b/BE/holder/src/holder/holder-api.controller.ts @@ -14,28 +14,31 @@ export class HolderAPIController { private readonly customLoggerService: CustomLoggerService, ) {} + @Post('/reg-did') + @ApiOperation({ + summary: 'Holder DID 생성 및 적재', + }) + async registerDID() { + try { + // DID를 Near 네트워크에 적재 + return await this.holderAPIService.loadDID(); + } catch (error) { + this.customLoggerService.error('/reg-did', 'Holder DID 생성 실패', {}); + throw new CustomErrorException('Register DID Failed', 500); + } + } + @Post('/create-vc') @ApiOperation({ summary: '사용자 VC 생성', }) async createUserVC(@Body() dto: UserVCDto) { try { - const { issuerPubKey, vc } = await this.holderAPIService.createUserVC( - dto, - ); - const { proofValue, message } = - await this.holderAPIService.getProofValue(); - const rawVC = JSON.parse(vc); - - const newProof = { ...rawVC.proof, proofValue }; - const newVC = { ...rawVC, proof: newProof }; - - // DID를 Near 네트워크에 적재 - // await this.holderAPIService.loadDID(); - + const { issuerPubKey, vc, message } = + await this.holderAPIService.createUserVC(dto); return { statusCode: 200, - data: { issuerPubKey, vc: JSON.stringify(newVC), message }, + data: { issuerPubKey, vc, message }, }; } catch (error) { this.customLoggerService.error('/create-vc', '사용자 VC 생성 실패', dto); diff --git a/BE/holder/src/holder/holder-api.service.ts b/BE/holder/src/holder/holder-api.service.ts index 4ad3b9c..1c99b20 100644 --- a/BE/holder/src/holder/holder-api.service.ts +++ b/BE/holder/src/holder/holder-api.service.ts @@ -22,7 +22,6 @@ export class HolderAPIService { ) {} CREATE_USER_VC = this.configService.get('API_CREATE_USER_VC'); - GET_PROOF_VALUE = this.configService.get('API_GET_PROOF_VALUE'); /* @ Use: Holder Controller - createUserVC() @@ -31,7 +30,7 @@ export class HolderAPIService { */ async createUserVC( dto: UserVCDto, - ): Promise<{ issuerPubKey: string; vc: string }> { + ): Promise<{ issuerPubKey: string; vc: string; message: string }> { return lastValueFrom( this.httpService .post(this.CREATE_USER_VC, { @@ -41,19 +40,6 @@ export class HolderAPIService { ); } - /* - @ Use: Holder Controller - createUserVC() - @ Intend: VC에 담을 proof value를 Issuer에게 생성 요청 - * API Call: Issuer - generateProofValue() - */ - async getProofValue(): Promise<{ proofValue: string; message: string }> { - return lastValueFrom( - this.httpService - .post(this.GET_PROOF_VALUE) - .pipe(map((response) => response?.data)), - ); - } - /* @ Use: Holder Controller - sendEmailCode() @ Intend: 사용자 이메일로 인증코드를 발송하여 2차 인증 @@ -88,11 +74,9 @@ export class HolderAPIService { */ async loadDID() { const contract = await connectToNEARContract(); - await (contract as NEARContract).reg_did_using_account({ - is_issuer: true, + is_issuer: false, }); - return true; } } diff --git a/BE/issuer/src/issuer/issuer-api.controller.ts b/BE/issuer/src/issuer/issuer-api.controller.ts index e5cb420..d6eb48d 100644 --- a/BE/issuer/src/issuer/issuer-api.controller.ts +++ b/BE/issuer/src/issuer/issuer-api.controller.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { Controller, Get, Query, Post, Body } from '@nestjs/common'; import { IssuerAPIService } from './issuer-api.service'; import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger'; @@ -22,13 +23,13 @@ export class IssuerAPIController { // 적재된 DID인지 확인: 아니라면 throw // await this.checkIsLoadedDID(dto.holderPubKey); - const { vc } = this.issuerAPIService.createUserVC(dto); + const { vc, message } = await this.issuerAPIService.createUserVC(dto); const vcString = JSON.stringify(vc); const issuerPubKey = this.issuerAPIService.getIssuerPubKey(); try { await this.issuerAPIService.loadKeyChain(issuerPubKey, vcString); - return { issuerPubKey, vc: vcString }; + return { issuerPubKey, vc: vcString, message }; } catch (error) { this.customLoggerService.error('/create-vc', '사용자 VC 생성 실패', { ...dto, diff --git a/BE/issuer/src/issuer/issuer-api.service.ts b/BE/issuer/src/issuer/issuer-api.service.ts index 1969a38..fecec8a 100644 --- a/BE/issuer/src/issuer/issuer-api.service.ts +++ b/BE/issuer/src/issuer/issuer-api.service.ts @@ -30,11 +30,15 @@ export class IssuerAPIService { @ Use: Issuer Controller - createUserVC() @ Intend: did 규격에 맞게 VC object 생성 */ - createUserVC(dto: UserVCDto) { + async createUserVC(dto: UserVCDto) { const { holderPubKey } = dto; const uuid = uuidv4(); - const vc = createVC(uuid, holderPubKey); - return { uuid, vc }; + + // proof value가 삽입된 VC 생성 + const { proofValue, message } = await this.generateProofValue(); + + const vc = createVC(uuid, holderPubKey, proofValue); + return { uuid, vc, message }; } /* diff --git a/BE/issuer/src/utils/utils.ts b/BE/issuer/src/utils/utils.ts index 5134c5d..af22c62 100644 --- a/BE/issuer/src/utils/utils.ts +++ b/BE/issuer/src/utils/utils.ts @@ -46,7 +46,11 @@ export async function connectToNEARContract(): Promise { return contract; } -export function createVC(uuid: string, holderPubKey: string) { +export function createVC( + uuid: string, + holderPubKey: string, + proofValue: string, +) { const timeStamp = getTimeStamp(); // proofValue 는 현재 하드코딩 됨 // - issuer 필드와 함께, 연산결과로 수정되어야 함 @@ -54,7 +58,7 @@ export function createVC(uuid: string, holderPubKey: string) { return { context: ['https://www.w3.org/ns/credentials/v2'], id: `url:uuid:${uuid}`, - credential_type: ['VerifiableCredential', 'MajorCredential'], + credential_type: ['VerifiableCredential'], // 완성본 issuer issuer: 'did:near:pnu.testnet', validFrom: timeStamp, @@ -70,7 +74,7 @@ export function createVC(uuid: string, holderPubKey: string) { created: timeStamp, verificationMethod: 'CircRefVCSignatureVerificationMethod', proofPurpose: 'assertionMethod', - proofValue: '', + proofValue, }, }; }