Skip to content

Commit b9917fc

Browse files
added verification test for signatures after conversion to and from b58
1 parent ff0627a commit b9917fc

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

deku-p/src/core/crypto/tests/alg_intf_tests.ml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ struct
5252
List.map (fun hash -> (Signature.sign sk hash, hash)) to_sign)
5353
secret_keys
5454

55+
let signatures_to_b58 =
56+
List.map
57+
(fun sig_list ->
58+
List.map
59+
(fun (signature, hash) -> (Signature.to_b58 signature, hash))
60+
sig_list)
61+
signatures
62+
63+
let b58_to_signatures =
64+
List.map
65+
(fun sig_list ->
66+
List.map
67+
(fun (b58, hash) -> (Option.get @@ Signature.of_b58 b58, hash))
68+
sig_list)
69+
signatures_to_b58
70+
5571
let verified_normal_signatures =
5672
let check_sig pk signatures =
5773
List.map
@@ -61,6 +77,16 @@ struct
6177
List.map2
6278
(fun key signatures -> check_sig key signatures)
6379
public_keys signatures
80+
81+
let verified_after_conversion =
82+
let check_sig pk signatures =
83+
List.map
84+
(fun (signature, hash) -> Signature.verify pk signature hash)
85+
signatures
86+
in
87+
List.map2
88+
(fun key signatures -> check_sig key signatures)
89+
public_keys b58_to_signatures
6490
end
6591

6692
module Test_secret_key_data = struct
@@ -161,5 +187,12 @@ struct
161187
~msg:"verified normal signatures are equal"
162188
~expected:Tezos_data.verified_normal_signatures
163189
~actual:Signature_data.verified_normal_signatures
190+
191+
(* We convert the signatures to b58 and back to ensure no data is lost *)
192+
let verified_after_conversion () =
193+
Alcotest.(check' (list (list bool)))
194+
~msg:"verified post conversion signatures are equal"
195+
~expected:Tezos_data.verified_after_conversion
196+
~actual:Signature_data.verified_after_conversion
164197
end
165198
end

deku-p/src/core/crypto/tests/test_ed25519.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,7 @@ let run () =
104104
test_case "signatures" `Quick Test_signature_data.signatures;
105105
test_case "verified normal signatures" `Quick
106106
Test_signature_data.verified_normal_signatures;
107+
test_case "verified after conversion signatures" `Quick
108+
Test_signature_data.verified_after_conversion;
107109
] );
108110
]

0 commit comments

Comments
 (0)