feat(server): xxhash

This commit is contained in:
Jonathan Jogenfors
2024-10-11 01:05:19 +02:00
parent 465f4639da
commit 0dbb0aabc9
15 changed files with 523 additions and 14 deletions

View File

@@ -801,7 +801,7 @@ export class AssetRepository implements IAssetRepository {
}
@GenerateSql({ params: [{ assetId: DummyValue.UUID, type: AssetFileType.PREVIEW, path: '/path/to/file' }] })
async upsertFile(file: { assetId: string; type: AssetFileType; path: string }): Promise<void> {
async upsertFile(file: { assetId: string; type: AssetFileType; path: string; checksum?: BigInt }): Promise<void> {
await this.fileRepository.upsert(file, { conflictPaths: ['assetId', 'type'] });
}

View File

@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import { xxh3 } from '@node-rs/xxhash';
import { compareSync, hash } from 'bcrypt';
import { createHash, createPublicKey, createVerify, randomBytes, randomUUID } from 'node:crypto';
import { createReadStream } from 'node:fs';
@@ -28,6 +29,10 @@ export class CryptoRepository implements ICryptoRepository {
return createHash('sha256').update(value).digest('base64');
}
xxHash(value: string) {
return xxh3.Xxh3.withSeed().update(value).digest();
}
verifySha256(value: string, encryptedValue: string, publicKey: string) {
const publicKeyBuffer = Buffer.from(publicKey, 'base64');
const cryptoPublicKey = createPublicKey({