almeira-web/facturacion-dian-hub/backend/src/domain/value-objects/SoftwareSecurityCode.ts

28 lines
768 B
TypeScript

import { createHash } from 'node:crypto';
/**
* Value Object para SoftwareSecurityCode requerido en las UBLExtensions de la DIAN
* Formula: SHA-384(SoftwareID + SoftwarePIN + NumeroFactura)
*/
export class SoftwareSecurityCode {
private readonly _hash: string;
private constructor(hash: string) {
this._hash = hash;
}
public static generar(softwareId: string, softwarePin: string, numeroFactura: string): SoftwareSecurityCode {
const raw = `${softwareId.trim()}${softwarePin.trim()}${numeroFactura.trim()}`;
const hash = createHash('sha384').update(raw, 'utf8').digest('hex');
return new SoftwareSecurityCode(hash);
}
public get hash(): string {
return this._hash;
}
public toString(): string {
return this._hash;
}
}