Skip to content

Commit e1f37ee

Browse files
authored
Merge pull request #1512 from input-output-hk/ensemble/1470/implement-cardano-transactions-verification-wasm
Implement Cardano transactions verification in `mithril-client-wasm`
2 parents 9eb6467 + f93058a commit e1f37ee

File tree

170 files changed

+6078
-638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+6078
-638
lines changed

.github/workflows/test-client.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ on:
3131
required: false
3232
type: string
3333
default: https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/pre-release-preview/genesis.vkey
34+
transactions_hashes_to_certify:
35+
description: Comma separated list of transactions hashes to test certification on.
36+
required: false
37+
type: string
3438
enable_debug:
3539
description: Enable debug output ("-vvv") for the mithril-client calls
3640
required: true
@@ -193,6 +197,7 @@ jobs:
193197
run: |
194198
echo "AGGREGATOR_ENDPOINT=${{ inputs.aggregator_endpoint }}" > ./www-test/.env
195199
echo "GENESIS_VERIFICATION_KEY=$(curl -s ${{ inputs.genesis_verification_key }})" >> ./www-test/.env
200+
echo "TRANSACTIONS_HASHES_TO_CERTIFY=${{ inputs.transactions_hashes_to_certify }}" >> ./www-test/.env
196201
197202
- name: Start the server
198203
working-directory: mithril-client-wasm

Cargo.lock

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"examples/client-mithril-stake-distribution",
99
"examples/client-snapshot",
1010
"mithril-aggregator",
11+
"mithril-build-script",
1112
"mithril-client",
1213
"mithril-client-cli",
1314
"mithril-client-wasm",

docs/website/root/glossary.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ A Cardano node is a node that runs in a [Cardano network](#cardano-network). The
2424

2525
A Cardano key pair is an asymmetric key pair used to identify a [stake pool operator](#stake-pool-operator-spo) on the [Cardano network](#cardano-network).
2626

27+
## Cardano transaction
28+
29+
A Cardano transaction proof is a cryptographic proof that a sub-set of Cardano transactions is included in the Cardano transactions set. It is generated upon request from a [Mithril client](#mithril-client) and is signed by a [certificate](#certificate).
30+
31+
A Cardano transactions set commitment represents, in a succinct way, the Cardano transactions set that was signed by Mithril at a given [Beacon](#beacon).
32+
2733
## Certificate
2834

2935
The Mithril aggregator combines the produced [multi-signature](#multi-signature) and some metadata into a Mithril certificate that will be later used by the [Mithril client](#mithril-client) to verify the authenticity of a [snapshot](#snapshot). The certificates are chained so that the [stake distribution](#stake-distribution) used to create the signatures is verifiably genuine.

docs/website/root/manual/developer-docs/nodes/mithril-client-library-wasm.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Mithril client library WASM can be used by Javascript developers to use the Mith
1414
It is responsible for handling the different types of data certified by Mithril, and available through a Mithril aggregator:
1515
- [**Snapshot**](../../../glossary.md#snapshot): list and get.
1616
- [**Mithril stake distribution**](../../../glossary.md#stake-distribution): list and get.
17+
- [**Cardano transaction**](../../../glossary.md#cardano-transaction): list & get commitments, get proofs
1718
- [**Certificate**](../../../glossary.md#certificate): list, get, and chain validation.
1819

1920
:::
@@ -113,6 +114,36 @@ let valid_stake_distribution_message = await client.verify_message_match_certifi
113114
console.log("valid_stake_distribution_message:", valid_stake_distribution_message);
114115
```
115116

117+
If the aggregator signs **CardanoTransactions**, you can add the code below to the previous example:
118+
119+
:::tip
120+
121+
You can verify that the aggregator signs **CardanoTransactions** by running the command below:
122+
123+
```bash
124+
wget -q -O - YOUR_AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])'
125+
```
126+
127+
For example with the aggregator on `testing-sanchonet` Mithril network:
128+
129+
```bash
130+
wget -q -O - https://aggregator.testing-sanchonet.api.mithril.network/aggregator | jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])'
131+
```
132+
133+
:::
134+
135+
```js
136+
const proof = await client.unstable.get_cardano_transaction_proofs(["CARDANO_TRANSACTION_HASH_1", "CARDANO_TRANSACTION_HASH_2"]);
137+
console.log("Proof tx hash", proof.transactions_hashes);
138+
console.log("Proof certificate hash", proof.certificate_hash);
139+
140+
let proof_certificate = await client.verify_certificate_chain(proof.certificate_hash);
141+
console.log("verify_certificate_chain OK, last_certificate_from_chain:", proof_certificate);
142+
143+
let valid_cardano_transaction_proof = await client.unstable.verify_cardano_transaction_proof_then_compute_message(proof, proof_certificate);
144+
console.log("valid_cardano_transaction_proof:", valid_cardano_transaction_proof);
145+
```
146+
116147
:::tip
117148

118149
You can read the complete [Rust developer documentation](https://mithril.network/rust-doc/mithril_client_wasm/index.html).

mithril-build-script/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
.DS_Store
3+

mithril-build-script/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "mithril-build-script"
3+
version = "0.1.0"
4+
description = "A toolbox for Mithril crates build scripts"
5+
authors = { workspace = true }
6+
edition = { workspace = true }
7+
homepage = { workspace = true }
8+
license = { workspace = true }
9+
repository = { workspace = true }
10+
11+
[dependencies]

mithril-build-script/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Mithril-build-script
2+
3+
A toolbox for Mithril crates that need a [build scripts phase](https://doc.rust-lang.org/cargo/reference/build-scripts.html).
4+
5+
Moreover, this crate allows to test the build scripts, which is not supported directly in `build.rs` (see: [rust-lang/cargo#1581](https://github.com/rust-lang/cargo/issues/1581)).

0 commit comments

Comments
 (0)