mirror of
https://github.com/selfxyz/self.git
synced 2026-01-15 01:28:18 -05:00
feat: Added tests for invaild mrz, signature and econtent.
This commit is contained in:
@@ -36,6 +36,15 @@ describe('Register - SHA1 WITH ECDSA', function () {
|
||||
k_dsc
|
||||
);
|
||||
|
||||
let qx = BigInt(hexToDecimal(inputs.dsc_modulus[0]));
|
||||
let qy = BigInt(hexToDecimal(inputs.dsc_modulus[1]));
|
||||
let dsc_modulus = [BigintToArray(43, 6, qx), BigintToArray(43, 6, qy)];
|
||||
|
||||
let signature = inputs.signature;
|
||||
let { r, s } = extractRSFromSignature(signature);
|
||||
let signature_r = BigintToArray(43, 6, BigInt(hexToDecimal(r)));
|
||||
let signature_s = BigintToArray(43, 6, BigInt(hexToDecimal(s)));
|
||||
|
||||
before(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, '../../circuits/register/register_ecdsaWithSHA1Encryption.circom'),
|
||||
@@ -105,4 +114,73 @@ describe('Register - SHA1 WITH ECDSA', function () {
|
||||
const commitment_js = commitment_bytes.toString();
|
||||
expect(commitment_circom).to.be.equal(commitment_js);
|
||||
});
|
||||
|
||||
it('should fail to calculate witness with invalid econtent', async function () {
|
||||
try {
|
||||
const invalidInputs = {
|
||||
secret: inputs.secret,
|
||||
mrz: inputs.mrz,
|
||||
dg1_hash_offset: inputs.dg1_hash_offset[0],
|
||||
econtent: inputs.econtent.map((byte: string) => String((parseInt(byte, 10) + 1) % 256)),
|
||||
datahashes_padded_length: inputs.datahashes_padded_length[0],
|
||||
signed_attributes: inputs.signed_attributes,
|
||||
signature_r: signature_r,
|
||||
signature_s: signature_s,
|
||||
dsc_modulus: dsc_modulus,
|
||||
dsc_secret: inputs.dsc_secret,
|
||||
attestation_id: inputs.attestation_id,
|
||||
};
|
||||
await circuit.calculateWitness(invalidInputs);
|
||||
expect.fail('Expected an error but none was thrown.');
|
||||
} catch (error) {
|
||||
expect(error.message).to.include('Assert Failed');
|
||||
}
|
||||
});
|
||||
|
||||
it('should fail to calculate witness with invalid mrz', async function () {
|
||||
try {
|
||||
const invalidInputs = {
|
||||
secret: inputs.secret,
|
||||
mrz: Array(93)
|
||||
.fill(0)
|
||||
.map((byte) => BigInt(byte).toString()),
|
||||
dg1_hash_offset: inputs.dg1_hash_offset[0],
|
||||
econtent: inputs.econtent,
|
||||
datahashes_padded_length: inputs.datahashes_padded_length[0],
|
||||
signed_attributes: inputs.signed_attributes,
|
||||
signature_r: signature_r,
|
||||
signature_s: signature_s,
|
||||
dsc_modulus: dsc_modulus,
|
||||
dsc_secret: inputs.dsc_secret,
|
||||
attestation_id: inputs.attestation_id,
|
||||
};
|
||||
await circuit.calculateWitness(invalidInputs);
|
||||
expect.fail('Expected an error but none was thrown.');
|
||||
} catch (error) {
|
||||
expect(error.message).to.include('Assert Failed');
|
||||
}
|
||||
});
|
||||
|
||||
it('should fail to calculate witness with invalid signature', async function () {
|
||||
let wrong_signature_s = BigintToArray(43, 6, BigInt(hexToDecimal(s) + 1));
|
||||
try {
|
||||
const invalidInputs = {
|
||||
secret: inputs.secret,
|
||||
mrz: inputs.mrz,
|
||||
dg1_hash_offset: inputs.dg1_hash_offset[0],
|
||||
econtent: inputs.econtent,
|
||||
datahashes_padded_length: inputs.datahashes_padded_length[0],
|
||||
signed_attributes: inputs.signed_attributes,
|
||||
signature_r: signature_r,
|
||||
signature_s: wrong_signature_s,
|
||||
dsc_modulus: dsc_modulus,
|
||||
dsc_secret: inputs.dsc_secret,
|
||||
attestation_id: inputs.attestation_id,
|
||||
};
|
||||
await circuit.calculateWitness(invalidInputs);
|
||||
expect.fail('Expected an error but none was thrown.');
|
||||
} catch (error) {
|
||||
expect(error.message).to.include('Assert Failed');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -64,8 +64,6 @@ export function getLeaf(pubkey: any, i?: number): bigint {
|
||||
sigAlgFormattedForCircuit === 'ecdsa_with_SHA512'
|
||||
) {
|
||||
try {
|
||||
// this will be replaced by just X and Y or pubkey in publicKeyQ
|
||||
|
||||
if (!pubkey.publicKeyQ) {
|
||||
throw new Error('publicKeyQ is undefined');
|
||||
}
|
||||
@@ -79,12 +77,9 @@ export function getLeaf(pubkey: any, i?: number): bigint {
|
||||
let qx = BigintToArray(43, 6, BigInt(hexToDecimal(x)));
|
||||
let qy = BigintToArray(43, 6, BigInt(hexToDecimal(y)));
|
||||
|
||||
// bigint_to_array();
|
||||
let poseidon_hasher_dsc_modules_x = poseidon6(qx);
|
||||
let poseidon_hasher_dsc_modules_y = poseidon6(qy);
|
||||
console.log(SignatureAlgorithm[sigAlgFormattedForCircuit], 's');
|
||||
|
||||
// ! @TODO check if this is correct
|
||||
return poseidon3([
|
||||
SignatureAlgorithm[sigAlgFormattedForCircuit],
|
||||
poseidon_hasher_dsc_modules_x, // pub.x
|
||||
|
||||
Reference in New Issue
Block a user