Skip to content

Commit

Permalink
refactor: adapt the WASM client example to work with new unstable imp…
Browse files Browse the repository at this point in the history
…lementation
  • Loading branch information
jpraynaud committed Sep 3, 2024
1 parent 75e1bfd commit da0c03e
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions mithril-client-wasm/www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ broadcast_channel.onmessage = (e) => {
displayMessageInDOM(
event.type,
"The certificate chain validation has started, event_id: " +
event.payload.certificate_chain_validation_id,
event.payload.certificate_chain_validation_id,
);
} else if (event.type == "CertificateValidated") {
displayMessageInDOM(
event.type,
"A certificate has been validated, certificate_hash: " +
event.payload.certificate_hash +
", event_id: " +
event.payload.certificate_chain_validation_id,
event.payload.certificate_hash +
", event_id: " +
event.payload.certificate_chain_validation_id,
);
} else if (event.type == "CertificateChainValidated") {
certificate_chain_validated_occurs = true;
Expand Down Expand Up @@ -64,21 +64,16 @@ function format_tx_list(transactions_hashes) {
return "<ul>" + transactions_hashes.map((tx) => "<li>" + tx + "</li>").join("") + "</ul>";
}

function client_options_with_custom_headers() {
// The following header is set as an example.
// It's used to demonstrate how to add headers.
let http_headers_map = new Map();
http_headers_map.set("Content-Type", "application/json");

return {
http_headers: http_headers_map,
};
}

await initMithrilClient();

let client_options = client_options_with_custom_headers();
let client = new MithrilClient(aggregator_endpoint, genesis_verification_key, client_options);
let client = new MithrilClient(aggregator_endpoint, genesis_verification_key, {
// The following header is set as an example.
// It's used to demonstrate how to add headers.
http_headers: new Map([["Content-Type", "application/json"]]),
// The following option activates the unstable features of the client.
// Unstable features will trigger an error if this option is not set.
unstable: true
});

displayStepInDOM(1, "Getting stake distributions list...");
let mithril_stake_distributions_list = await client.list_mithril_stake_distributions();
Expand All @@ -104,8 +99,8 @@ console.log("last_stake_distribution:", last_stake_distribution);
displayStepInDOM(
3,
"Getting Mithril certificate from certificate hash: " +
last_stake_distribution.certificate_hash +
"...",
last_stake_distribution.certificate_hash +
"...",
);
let certificate = await client.get_mithril_certificate(last_stake_distribution.certificate_hash);
displayMessageInDOM("Result", "got Mithril certificate &#x2713;");
Expand Down Expand Up @@ -135,7 +130,7 @@ displayMessageInDOM("Result", "Mithril stake distribution message validated &#x2
console.log("valid_stake_distribution_message:", valid_stake_distribution_message);

displayStepInDOM(7, "Getting transaction proof...");
const proof = await client.unstable.get_cardano_transaction_proofs([
const proof = await client.get_cardano_transaction_proofs([
"eac09f970f47ef3ab378db9232914e146773853397e79b904f1a45123a23c21f",
"81fe7a5dab42867ef309b6d7210158bf99331884ac3c3b6c7188a8c9c18d5974",
"320c13f4a3e51f6f4f66fcd9007e02bf658aa4ee9a88a509028d867d3b8a8e9a",
Expand All @@ -157,7 +152,7 @@ displayMessageInDOM("Result", "certificate chain verified &#x2713;");
console.log("verify_certificate_chain OK, last_certificate_from_chain:", proof_certificate);

displayStepInDOM(10, "Validating Cardano transaction proof message...");
let protocol_message = await client.unstable.verify_cardano_transaction_proof_then_compute_message(
let protocol_message = await client.verify_cardano_transaction_proof_then_compute_message(
proof,
proof_certificate,
);
Expand Down

0 comments on commit da0c03e

Please sign in to comment.