UNPKG

nft-folder-blockchain-connector-besu

Version:

A NestJS-based blockchain connector that communicates with specific smart contracts from the NFT Folder project.

157 lines 6.76 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataIntegrityController = void 0; const common_1 = require("@nestjs/common"); const platform_express_1 = require("@nestjs/platform-express"); const swagger_1 = require("@nestjs/swagger"); const data_integrity_service_1 = require("./service/data-integrity.service"); let DataIntegrityController = class DataIntegrityController { dataIntegrityService; constructor(dataIntegrityService) { this.dataIntegrityService = dataIntegrityService; } hashFile(fileToHash) { if (!fileToHash) { throw new common_1.BadRequestException('A file must be provided'); } const dataToHash = fileToHash.buffer; return this.dataIntegrityService.hashData(dataToHash); } async verifyFile(fileToHash, body) { if (!fileToHash) { throw new common_1.BadRequestException('A file must be provided'); } const dataToHash = fileToHash.buffer; return this.dataIntegrityService.verifyData(dataToHash, body.originalHash); } hashString(body) { if (!body.stringToHash) { throw new common_1.BadRequestException('A string must be provided'); } const dataToHash = Buffer.from(body.stringToHash); return this.dataIntegrityService.hashData(dataToHash); } async verifyString(body) { if (!body.stringToHash) { throw new common_1.BadRequestException('A string must be provided'); } const dataToHash = Buffer.from(body.stringToHash); return this.dataIntegrityService.verifyData(dataToHash, body.originalHash); } }; exports.DataIntegrityController = DataIntegrityController; __decorate([ (0, common_1.Post)('files/hash'), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: 'Hash a file and return its hash' }), (0, swagger_1.ApiConsumes)('multipart/form-data'), (0, swagger_1.ApiBody)({ schema: { type: 'object', properties: { fileToHash: { type: 'string', format: 'binary', description: 'The file to hash (e.g., PDF, image, etc.)', }, }, }, }), (0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('fileToHash')), __param(0, (0, common_1.UploadedFile)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", String) ], DataIntegrityController.prototype, "hashFile", null); __decorate([ (0, common_1.Post)('files/verify'), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: 'Verify if a file has the same hash as its original hash' }), (0, swagger_1.ApiConsumes)('multipart/form-data'), (0, swagger_1.ApiBody)({ schema: { type: 'object', properties: { fileToHash: { type: 'string', format: 'binary', description: 'The file to hash (e.g., PDF, image, etc.)', }, originalHash: { type: 'string', format: 'hexadecimal', description: 'The original hash of the file, represented as a 64-character hexadecimal string', }, }, }, }), (0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('fileToHash')), __param(0, (0, common_1.UploadedFile)()), __param(1, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], DataIntegrityController.prototype, "verifyFile", null); __decorate([ (0, common_1.Post)('strings/hash'), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: 'Hash a string and return its hash' }), (0, swagger_1.ApiBody)({ schema: { type: 'object', properties: { stringToHash: { type: 'string', description: 'The string to hash', }, }, }, }), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", String) ], DataIntegrityController.prototype, "hashString", null); __decorate([ (0, common_1.Post)('strings/verify'), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: 'Verify if a string has the same hash as its original hash' }), (0, swagger_1.ApiBody)({ schema: { type: 'object', properties: { stringToHash: { type: 'string', description: 'The string to hash', }, originalHash: { type: 'string', format: 'hexadecimal', description: 'The original hash of the string, represented as a 64-character hexadecimal string', }, }, }, }), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], DataIntegrityController.prototype, "verifyString", null); exports.DataIntegrityController = DataIntegrityController = __decorate([ (0, common_1.Controller)('data-integrities'), (0, swagger_1.ApiTags)('Data Integrities'), __metadata("design:paramtypes", [data_integrity_service_1.DataIntegrityService]) ], DataIntegrityController); //# sourceMappingURL=data-integrity.controller.js.map