From fc149cbb01bd82b784036c1bff6e634f87fbfa79 Mon Sep 17 00:00:00 2001 From: 0xturboblitz Date: Fri, 18 Aug 2023 13:25:40 +0200 Subject: [PATCH] clean --- app/scripts/mrzToSig.ts | 21 +++++++++++++++++++++ app/utils/utils.ts | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/scripts/mrzToSig.ts b/app/scripts/mrzToSig.ts index 24bf33876..cb759a16e 100644 --- a/app/scripts/mrzToSig.ts +++ b/app/scripts/mrzToSig.ts @@ -80,6 +80,15 @@ const md = forge.md.sha256.create(); md.update(forge.util.binary.raw.encode(new Uint8Array(eContent))); const hashOfEContent = md.digest().getBytes(); +console.log('modulus', hexToDecimal(modulus)); +console.log('eContent', bytesToBigDecimal(passportData.eContent)); +console.log('signature', bytesToBigDecimal(passportData.encryptedDigest)); +// Convert the hash to a single decimal number + +const hashBigNumber = BigInt('0x' + forge.util.bytesToHex(hashOfEContent)); + +console.log('hashOfEContent in big decimal', hashBigNumber.toString()); + // Signature verification const signatureBytes = Buffer.from(passportData.encryptedDigest).toString( 'binary', @@ -97,3 +106,15 @@ function hash(bytesArray: number[]): number[] { hash.update(Buffer.from(bytesArray)); return Array.from(hash.digest()).map(x => (x < 128 ? x : x - 256)); } + +function bytesToBigDecimal(arr: number[]): string { + let result = BigInt(0); + for (let i = 0; i < arr.length; i++) { + result = result * BigInt(256) + BigInt(arr[i] & 0xff); + } + return result.toString(); +} + +function hexToDecimal(hex: string): string { + return BigInt(`0x${hex}`).toString(); +} diff --git a/app/utils/utils.ts b/app/utils/utils.ts index 691a6312c..af0711e37 100644 --- a/app/utils/utils.ts +++ b/app/utils/utils.ts @@ -89,8 +89,8 @@ export function parsePubKeyString(pubKeyString: string) { const modulus = modulusMatch ? modulusMatch[1] : null; const exponent = publicExponentMatch ? publicExponentMatch[1] : null; - console.log('Modulus:', modulus); - console.log('Public Exponent:', exponent); + // console.log('Modulus:', modulus); + // console.log('Public Exponent:', exponent); if (!modulus || !exponent) { throw new Error('Could not parse public key string');