mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
* add common sdk * remove sdk backend api * remove registry * regenerate sha256 rsa dsc each time * download ski-pem dynamically on staging, refactor initpassportDataParsing * add state machine for button on prove screen, improve ux on splash screen * fetch ski-pem in production * fix linter issues * fix prove screen button bugs * update podfile.lock and yarn.lock * run linter in circuits repo * bump build * bump version for sentry debugging * bump ios to version 118 --------- Co-authored-by: Justin Hernandez <transphorm@gmail.com>
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import { expect } from 'chai';
|
|
import { describe, it } from 'mocha';
|
|
import { genAndInitMockPassportData } from '../src/utils/passports/genMockPassportData';
|
|
import { parsePassportData } from '../src/utils/passports/passport_parsing/parsePassportData';
|
|
import { PassportData, SignatureAlgorithm } from '../src/utils/types';
|
|
|
|
const testCases = [
|
|
{ dgHashAlgo: 'sha1', eContentHashAlgo: 'sha1', sigAlg: 'rsa_sha1_65537_2048' },
|
|
{ dgHashAlgo: 'sha1', eContentHashAlgo: 'sha1', sigAlg: 'rsa_sha256_65537_2048' },
|
|
{ dgHashAlgo: 'sha256', eContentHashAlgo: 'sha256', sigAlg: 'rsapss_sha256_65537_2048' },
|
|
{ dgHashAlgo: 'sha256', eContentHashAlgo: 'sha256', sigAlg: 'ecdsa_sha256_secp256r1_256' },
|
|
{ dgHashAlgo: 'sha256', eContentHashAlgo: 'sha256', sigAlg: 'ecdsa_sha256_brainpoolP256r1_256' },
|
|
{ dgHashAlgo: 'sha1', eContentHashAlgo: 'sha1', sigAlg: 'ecdsa_sha1_secp256r1_256' },
|
|
];
|
|
|
|
|
|
describe('Mock Passport Data Generator', function () {
|
|
this.timeout(0);
|
|
|
|
testCases.forEach(({ dgHashAlgo, eContentHashAlgo, sigAlg }) => {
|
|
it(`should generate valid passport data for ${sigAlg}`, () => {
|
|
const passportData = genAndInitMockPassportData(
|
|
dgHashAlgo,
|
|
eContentHashAlgo,
|
|
sigAlg as SignatureAlgorithm,
|
|
'FRA',
|
|
'000101',
|
|
'300101'
|
|
);
|
|
expect(verify(passportData, dgHashAlgo, eContentHashAlgo, sigAlg)).to.be.true;
|
|
});
|
|
});
|
|
});
|
|
|
|
function verify(
|
|
passportData: PassportData,
|
|
dgHashAlgo: string,
|
|
eContentHashAlgo: string,
|
|
sigAlg: string
|
|
): boolean {
|
|
const passportMetaData = parsePassportData(passportData);
|
|
// console.log('passportMetaData', passportMetaData);
|
|
|
|
expect(passportMetaData.dg1HashFunction).to.equal(dgHashAlgo);
|
|
expect(passportMetaData.eContentHashFunction).to.equal(eContentHashAlgo);
|
|
|
|
// regex to find the signature algorithm (ecdsa or rsa/rsapss) before first underscore
|
|
const signatureAlgorithm = sigAlg.match(/^([^_]+)/)?.[1];
|
|
|
|
expect(passportMetaData.signatureAlgorithm).to.equal(signatureAlgorithm);
|
|
|
|
return true;
|
|
}
|