import { Injectable } from '@nestjs/common' ; import { RequiredExcept } from '@fc/common' ; import { ConfigService } from '@fc/config' ; import { CryptographyService } from '@fc/cryptography' ; import { LoggerService } from '@fc/logger' ; import { CryptographyFcpConfig } from './dto/cryptography-fcp-config' ; import { IPivotIdentity } from './interfaces/pivot-identity.interface' ; @ Injectable ( ) export class CryptographyFcpService { constructor ( private readonly logger , private readonly crypto , private readonly config ) { this . logger . setContext ( this . constructor . name ) ; } param pivotIdentity returns computeIdentityHash ( pivotIdentity ) { const serial = pivotIdentity . given_name + pivotIdentity . family_name + pivotIdentity . birthdate + pivotIdentity . gender + pivotIdentity . birthplace + pivotIdentity . birthcountry ; this . logger . trace ( { pivotIdentity } ) ; return this . crypto . hash ( serial , 'binary' , 'sha256' , 'base64' ) ; } param providerRef param identityHash returns computeSubV1 ( providerRef , identityHash ) { const { subSecretKey } = this . config . get < CryptographyFcpConfig > ( 'CryptographyFcp' ) ; const data = [ providerRef , identityHash , subSecretKey ] ; const sub = `${ this . crypto . hash ( data . join ( '' ) ) }v1` ; this . logger . trace ( { providerRef , identityHash , data , sub } ) ; return sub ; } }