@@ -4,7 +4,7 @@ import initMithrilClient, { MithrilClient } from "@mithril-dev/mithril-client-wa
4
4
let aggregator_endpoint = "https://aggregator.testing-sanchonet.api.mithril.network/aggregator" ;
5
5
let genesis_verification_key =
6
6
"5b3132372c37332c3132342c3136312c362c3133372c3133312c3231332c3230372c3131372c3139382c38352c3137362c3139392c3136322c3234312c36382c3132332c3131392c3134352c31332c3233322c3234332c34392c3232392c322c3234392c3230352c3230352c33392c3233352c34345d" ;
7
-
7
+ let certificate_chain_validated_occurs = false ;
8
8
const broadcast_channel = new BroadcastChannel ( "mithril-client" ) ;
9
9
broadcast_channel . onmessage = ( e ) => {
10
10
let event = e . data ;
@@ -13,12 +13,20 @@ broadcast_channel.onmessage = (e) => {
13
13
} else if ( event . type == "CertificateValidated" ) {
14
14
displayMessageInDOM ( event . type , "A certificate has been validated, certificate_hash: " + event . payload . certificate_hash + ", event_id: " + event . payload . certificate_chain_validation_id ) ;
15
15
} else if ( event . type == "CertificateChainValidated" ) {
16
+ certificate_chain_validated_occurs = true ;
16
17
displayMessageInDOM ( event . type , "The certificate chain is valid, event_id: " + event . payload . certificate_chain_validation_id ) ;
17
18
} else {
18
19
displayMessageInDOM ( event ) ;
19
20
}
20
21
} ;
21
22
23
+ async function waitUntilCertificateChainValidatedOccursOrTimeout ( ) {
24
+ for ( let i = 0 ; i < 100 && ! certificate_chain_validated_occurs ; i ++ ) {
25
+ await new Promise ( r => setTimeout ( r , 100 ) ) ;
26
+ }
27
+ certificate_chain_validated_occurs = false ;
28
+ }
29
+
22
30
function displayMessageInDOM ( subject , message ) {
23
31
let div = document . createElement ( 'div' ) ;
24
32
div . innerHTML = '<strong>' + subject + ': </strong>' + message ;
@@ -33,6 +41,10 @@ function displayStepInDOM(number, content) {
33
41
document . body . appendChild ( div ) ;
34
42
}
35
43
44
+ function format_tx_list ( transactions_hashes ) {
45
+ return "<ul>" + transactions_hashes . map ( ( tx ) => "<li>" + tx + "</li>" ) . join ( "" ) + "</ul>"
46
+ }
47
+
36
48
await initMithrilClient ( ) ;
37
49
38
50
let client = new MithrilClient (
@@ -60,6 +72,7 @@ console.log("certificate:", certificate);
60
72
61
73
displayStepInDOM ( 4 , "Verifying certificate chain..." ) ;
62
74
let last_certificate_from_chain = await client . verify_certificate_chain ( certificate . hash ) ;
75
+ await waitUntilCertificateChainValidatedOccursOrTimeout ( ) ;
63
76
displayMessageInDOM ( "Result" , "certificate chain verified ✓" ) ;
64
77
console . log ( "verify_certificate_chain OK, last_certificate_from_chain:" , last_certificate_from_chain ) ;
65
78
@@ -74,16 +87,24 @@ displayMessageInDOM("Result", "Mithril stake distribution message validated 
74
87
console . log ( "valid_stake_distribution_message:" , valid_stake_distribution_message ) ;
75
88
76
89
displayStepInDOM ( 7 , "Getting transaction proof..." ) ;
77
- const proof = await client . unstable . get_cardano_transaction_proofs ( [ "eac09f970f47ef3ab378db9232914e146773853397e79b904f1a45123a23c21f" ] ) ;
78
- displayMessageInDOM ( "Proof tx hash" , proof . transactions_hashes ) ;
79
- displayMessageInDOM ( "Proof certificate hash" , proof . certificate_hash ) ;
90
+ const proof = await client . unstable . get_cardano_transaction_proofs ( [ "eac09f970f47ef3ab378db9232914e146773853397e79b904f1a45123a23c21f" , "81fe7a5dab42867ef309b6d7210158bf99331884ac3c3b6c7188a8c9c18d5974" , "320c13f4a3e51f6f4f66fcd9007e02bf658aa4ee9a88a509028d867d3b8a8e9a" ] ) ;
91
+ displayMessageInDOM ( "Certificate hash of the returned proof" , proof . certificate_hash ) ;
92
+ displayMessageInDOM ( "Transactions hashes included in the proof" , format_tx_list ( proof . transactions_hashes ) ) ;
93
+ displayMessageInDOM ( "Transactions hashes not included in the proof" , format_tx_list ( proof . non_certified_transactions ) ) ;
80
94
81
95
displayStepInDOM ( 9 , "Verifying certificate chain..." ) ;
82
96
let proof_certificate = await client . verify_certificate_chain ( proof . certificate_hash ) ;
97
+ await waitUntilCertificateChainValidatedOccursOrTimeout ( ) ;
83
98
displayMessageInDOM ( "Result" , "certificate chain verified ✓" ) ;
84
99
console . log ( "verify_certificate_chain OK, last_certificate_from_chain:" , proof_certificate ) ;
85
100
86
101
displayStepInDOM ( 10 , "Validating Cardano transaction proof message..." ) ;
87
- let valid_cardano_transaction_proof = await client . unstable . verify_cardano_transaction_proof_then_compute_message ( proof , proof_certificate ) ;
88
- displayMessageInDOM ( "Result" , "Cardano transaction proof message validated ✓" ) ;
89
- console . log ( "valid_cardano_transaction_proof:" , valid_cardano_transaction_proof ) ;
102
+ let protocol_message = await client . unstable . verify_cardano_transaction_proof_then_compute_message ( proof , proof_certificate ) ;
103
+ console . log ( "Ensuire that the proof is indeed signed in the associated certificate" ) ;
104
+ if ( ( await client . verify_message_match_certificate ( protocol_message , proof_certificate ) ) === true ) {
105
+ displayMessageInDOM ( "Result" , "The proof is signed in the associated certificate ✓" ) ;
106
+ } else {
107
+ displayMessageInDOM ( "Result" , "Proof and certificate doesn't match ✗" ) ;
108
+ }
109
+ displayMessageInDOM ( "Transactions hashes certified" , format_tx_list ( proof . transactions_hashes ) ) ;
110
+ displayMessageInDOM ( "Transactions hashes not certified" , format_tx_list ( proof . non_certified_transactions ) ) ;
0 commit comments