import * as crypto from 'crypto'; // On a la donnée de base : const dg1File = { length: 91, mrzInfo: { compositeCheckDigit: '2', dateOfBirth: '000719', dateOfBirthCheckDigit: '1', dateOfExpiry: '291209', dateOfExpiryCheckDigit: '5', documentCode: 'P', documentNumber: '19HA34828', documentNumberCheckDigit: '4', documentType: 3, gender: 'MALE', issuingState: 'FRA', nationality: 'FRA', optionalData1: '<<<<<<<<<<<<<<0', primaryIdentifier: 'TAVERNIER', secondaryIdentifier: 'FLORENT { const dataHash = dataHashes[key as keyof typeof dataHashes]; return [Number(key), dataHash]; }) .sort((a, b) => (a[0] as number) - (b[0] as number)); console.log('dataHashesAsArray:', dataHashesAsArray); console.log('mrz: ', mrz); const mrzCharcodes = [...mrz].map(char => char.charCodeAt(0)); console.log('mrzCharcodes:', mrzCharcodes); mrzCharcodes.unshift(88); // the length of the mrz data mrzCharcodes.unshift(95, 31); // the MRZ_INFO_TAG mrzCharcodes.unshift(91); // the new length of the whole array mrzCharcodes.unshift(97); // the tag for DG1 console.log('mrzCharcodes with tags:', mrzCharcodes); const hash = crypto.createHash('sha256'); hash.update(Buffer.from(mrzCharcodes)); const mrzHash = Array.from(hash.digest()).map(x => (x < 128 ? x : x - 256)); // Ça correspond bien : console.log('mrzHash:', mrzHash); console.log('dataHashes["1"]:', dataHashes['1']); // Let's replace the first array with the MRZ hash dataHashesAsArray.shift(); dataHashesAsArray.unshift([1, mrzHash]); // Concaténons les dataHashes : const concatenatedDataHashes: number[] = [].concat( ...dataHashesAsArray.map((dataHash: any) => { dataHash[1].unshift(...[48, 37, 2, 1, dataHash[0], 4, 32]); return dataHash[1]; }), ); // Starting sequence. Should be the same for everybody, but not sure concatenatedDataHashes.unshift( ...[ 48, -126, 1, 37, 2, 1, 0, 48, 11, 6, 9, 96, -122, 72, 1, 101, 3, 4, 2, 1, 48, -126, 1, 17, ], ); // They are equal ! console.log('concatenatedDataHashes', concatenatedDataHashes); console.log('contentBytes', contentBytes);