Skip to content

Commit

Permalink
added verification test for signatures after conversion to and from b58
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteSwerve committed Dec 14, 2022
1 parent 45f69df commit f0482d1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions deku-p/src/core/crypto/tests/alg_intf_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ struct
List.map (fun hash -> (Signature.sign sk hash, hash)) to_sign)
secret_keys

let signatures_to_b58 =
List.map
(fun sig_list ->
List.map
(fun (signature, hash) -> (Signature.to_b58 signature, hash))
sig_list)
signatures

let b58_to_signatures =
List.map
(fun sig_list ->
List.map
(fun (b58, hash) -> (Option.get @@ Signature.of_b58 b58, hash))
sig_list)
signatures_to_b58

let verified_normal_signatures =
let check_sig pk signatures =
List.map
Expand All @@ -61,6 +77,16 @@ struct
List.map2
(fun key signatures -> check_sig key signatures)
public_keys signatures

let verified_after_conversion =
let check_sig pk signatures =
List.map
(fun (signature, hash) -> Signature.verify pk signature hash)
signatures
in
List.map2
(fun key signatures -> check_sig key signatures)
public_keys b58_to_signatures
end

module Test_secret_key_data = struct
Expand Down Expand Up @@ -161,5 +187,12 @@ struct
~msg:"verified normal signatures are equal"
~expected:Tezos_data.verified_normal_signatures
~actual:Signature_data.verified_normal_signatures

(* We convert the signatures to b58 and back to ensure no data is lost *)
let verified_after_conversion () =
Alcotest.(check' (list (list bool)))
~msg:"verified post conversion signatures are equal"
~expected:Tezos_data.verified_after_conversion
~actual:Signature_data.verified_after_conversion
end
end
2 changes: 2 additions & 0 deletions deku-p/src/core/crypto/tests/test_ed25519.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,7 @@ let run () =
test_case "signatures" `Quick Test_signature_data.signatures;
test_case "verified normal signatures" `Quick
Test_signature_data.verified_normal_signatures;
test_case "verified after conversion signatures" `Quick
Test_signature_data.verified_after_conversion;
] );
]

0 comments on commit f0482d1

Please sign in to comment.