From 144fc879688d2afc52100b0f835993f5e781c568 Mon Sep 17 00:00:00 2001 From: 0xturboblitz Date: Sat, 8 Jun 2024 18:21:57 +0200 Subject: [PATCH] SHA384withECDSA mock passport data --- circuits/package.json | 3 +- .../genMockPassportData/SHA384withECDSA.ts | 106 ++++++++++++++++++ circuits/yarn.lock | 13 +++ common/package.json | 1 + common/src/utils/mockPassportData.ts | 48 ++++++++ common/src/utils/utils.ts | 5 +- common/yarn.lock | 5 + 7 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 circuits/scripts/genMockPassportData/SHA384withECDSA.ts diff --git a/circuits/package.json b/circuits/package.json index 876c60c48..0cda3ec9e 100644 --- a/circuits/package.json +++ b/circuits/package.json @@ -22,6 +22,7 @@ "circom_tester": "github:Atomic-Buy/circom_tester#main", "circomlib": "^2.0.5", "circomlibjs": "^0.1.7", + "elliptic": "^6.5.5", "js-sha256": "^0.10.1", "node-forge": "^1.3.1", "poseidon-lite": "^0.2.0", @@ -37,4 +38,4 @@ "ts-mocha": "^10.0.0", "ts-node": "^10.9.2" } -} \ No newline at end of file +} diff --git a/circuits/scripts/genMockPassportData/SHA384withECDSA.ts b/circuits/scripts/genMockPassportData/SHA384withECDSA.ts new file mode 100644 index 000000000..6a69b25e7 --- /dev/null +++ b/circuits/scripts/genMockPassportData/SHA384withECDSA.ts @@ -0,0 +1,106 @@ +import assert from "assert"; +import { PassportData } from "../../../common/src/utils/types"; +import { hash, assembleEContent, formatAndConcatenateDataHashes, formatMrz, arraysAreEqual } from "../../../common/src/utils/utils"; +import * as forge from 'node-forge'; +import { writeFileSync } from "fs"; +import elliptic from 'elliptic'; +import * as crypto from 'crypto'; + +const sampleMRZ = "P char.charCodeAt(0)); @@ -151,9 +152,11 @@ export function hash(signatureAlgorithm: string, bytesArray: number[]) { const unsignedBytesArray = bytesArray.map(toUnsignedByte); const hash = (signatureAlgorithm == 'sha1WithRSAEncryption') ? sha1(unsignedBytesArray) + : (signatureAlgorithm == 'SHA384withECDSA') + ? sha384(unsignedBytesArray) : (signatureAlgorithm == 'sha256WithRSAEncryption' || signatureAlgorithm == 'rsassaPss') ? sha256(unsignedBytesArray) - : sha256(unsignedBytesArray); //defaults to sha256 + : sha256(unsignedBytesArray); // defaults to sha256 return hexToSignedBytes(hash); } diff --git a/common/yarn.lock b/common/yarn.lock index aa5da5526..4277edf4e 100644 --- a/common/yarn.lock +++ b/common/yarn.lock @@ -69,6 +69,11 @@ js-sha256@^0.10.1: resolved "https://registry.npmjs.org/js-sha256/-/js-sha256-0.10.1.tgz" integrity sha512-5obBtsz9301ULlsgggLg542s/jqtddfOpV5KJc4hajc9JV8GeY2gZHSVpYBn4nWqAUTJ9v+xwtbJ1mIBgIH5Vw== +js-sha512@^0.9.0: + version "0.9.0" + resolved "https://registry.yarnpkg.com/js-sha512/-/js-sha512-0.9.0.tgz#ed569aa1e4bdaf0b83363c29db1ab87b1192d9ae" + integrity sha512-mirki9WS/SUahm+1TbAPkqvbCiCfOAAsyXeHxK1UkullnJVVqoJG2pL9ObvT05CN+tM7fxhfYm0NbXn+1hWoZg== + node-forge@^1.3.1: version "1.3.1" resolved "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz"