Skip to content

Commit

Permalink
delete prev file, add tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
0xturboblitz committed Jun 2, 2024
1 parent 959836c commit 9101f6a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 135 deletions.
126 changes: 0 additions & 126 deletions circuits/scripts/genMockPassportData.ts

This file was deleted.

9 changes: 9 additions & 0 deletions circuits/scripts/genMockPassportData/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# How to generate mock passport data based on your real data?

- Build the app and scan your passport to log your passport data.
- Copy one of the files of this folder and paste your passport data.
- Adapt the `verify` function to verify it. Once this is done, adapt the `genMockPassportData` to generate a mock one.
- Once the mock passport data generated is verified correctly by the same `verify` function that verifies yours, you're all set!
- Run the script to generate a mock passport data and add it to `common/src/utils/mockPassportData.ts`
- Do a PR
- DM us to collect your bounty!
19 changes: 10 additions & 9 deletions common/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LeanIMT } from '@zk-kit/lean-imt';
import { assert } from './shaPad';
import { sha256 } from 'js-sha256';
//import {sha1} from 'js-sha1';
import { sha1 } from 'js-sha1';

export function formatMrz(mrz: string) {
const mrzCharcodes = [...mrz].map(char => char.charCodeAt(0));
Expand Down Expand Up @@ -63,7 +62,6 @@ export function formatAndConcatenateDataHashes(

export function assembleEContent(
messageDigest: number[],
timeOfSignature: number[],
) {
const constructedEContent = [];

Expand All @@ -82,8 +80,8 @@ export function assembleEContent(
constructedEContent.push(
...[48, 28, 6, 9, 42, -122, 72, -122, -9, 13, 1, 9, 5],
);
// time of the signature
constructedEContent.push(...timeOfSignature);
// mock time of signature
constructedEContent.push(...[49, 15, 23, 13, 49, 57, 49, 50, 49, 54, 49, 55, 50, 50, 51, 56, 90]);
// 1.2.840.113549.1.9.4 is RFC_3369_MESSAGE_DIGEST_OID
constructedEContent.push(
...[48, 47, 6, 9, 42, -122, 72, -122, -9, 13, 1, 9, 4],
Expand Down Expand Up @@ -150,9 +148,12 @@ export function hexToDecimal(hex: string): string {

// hash logic here because the one in utils.ts only works with node
export function hash(signatureAlgorithm: string, bytesArray: number[]) {
let unsignedBytesArray = bytesArray.map(toUnsignedByte);
let hash = (signatureAlgorithm == 'sha1WithRSAEncryption') ?
sha1(unsignedBytesArray) : sha256(unsignedBytesArray);
const unsignedBytesArray = bytesArray.map(toUnsignedByte);
const hash = (signatureAlgorithm == 'sha1WithRSAEncryption')
? sha1(unsignedBytesArray)
: (signatureAlgorithm == 'sha256WithRSAEncryption' || signatureAlgorithm == 'rsassaPss')
? sha256(unsignedBytesArray)
: sha256(unsignedBytesArray); //defaults to sha256
return hexToSignedBytes(hash);
}

Expand Down Expand Up @@ -260,4 +261,4 @@ export function generateMerkleProof(imt: LeanIMT, _index: number, maxDepth: numb
}
}
return { merkleProofSiblings, merkleProofIndices, depthForThisOne }
}
}

0 comments on commit 9101f6a

Please sign in to comment.