@@ -15,7 +15,8 @@ It is responsible for handling the different types of data certified by Mithril,
15
15
16
16
- [ ** Snapshot** ] ( ../../../glossary.md#snapshot ) : list and get.
17
17
- [ ** Mithril stake distribution** ] ( ../../../glossary.md#stake-distribution ) : list and get.
18
- - [ ** Cardano transaction** ] ( ../../../glossary.md#cardano-transaction ) : list & get snapshots, get proofs
18
+ - [ ** Cardano transaction** ] ( ../../../glossary.md#cardano-transaction ) : list & get snapshots, get proofs.
19
+ - [ ** Cardano stake distribution** ] ( ../../../glossary.md#stake-distribution ) : list, get and get by epoch.
19
20
- [ ** Certificate** ] ( ../../../glossary.md#certificate ) : list, get, and chain validation.
20
21
21
22
:::
@@ -93,10 +94,11 @@ broadcast_channel.onmessage = (e) => {
93
94
94
95
await initMithrilClient ();
95
96
96
- let client = await new MithrilClient (
97
- aggregator_endpoint,
98
- genesis_verification_key,
99
- );
97
+ let client = new MithrilClient (aggregator_endpoint, genesis_verification_key, {
98
+ // The following option activates the unstable features of the client.
99
+ // Unstable features will trigger an error if this option is not set.
100
+ unstable: true ,
101
+ });
100
102
let mithril_stake_distributions_list =
101
103
await client .list_mithril_stake_distributions ();
102
104
console .log (" stake distributions:" , mithril_stake_distributions_list);
@@ -145,6 +147,28 @@ console.log(
145
147
);
146
148
```
147
149
150
+ :::tip Adding Custom HTTP Headers
151
+
152
+ You can customize the HTTP headers sent by the Mithril client. This is particularly useful in scenarios where the Mithril client is used with a proxy, as it allows you to include headers like ** Authorization** or custom headers for specific use cases. Below is an example of how to set custom headers:
153
+
154
+ ``` js
155
+ let http_headers_map = new Map ();
156
+ http_headers_map .set (" Authorization" , " Bearer YourBearerToken" );
157
+ http_headers_map .set (" X-Custom-Header" , " YourCustomHeaderValue" );
158
+
159
+ let client_options = {
160
+ http_headers: http_headers_map,
161
+ };
162
+
163
+ let client = new MithrilClient (
164
+ aggregator_endpoint,
165
+ genesis_verification_key,
166
+ client_options,
167
+ );
168
+ ```
169
+
170
+ :::
171
+
148
172
If the aggregator signs ** CardanoTransactions** , you can add the code below to the previous example:
149
173
150
174
::: tip
@@ -155,16 +179,16 @@ You can verify that the aggregator signs **CardanoTransactions** by running the
155
179
wget -q -O - YOUR_AGGREGATOR_ENDPOINT | jq ' .capabilities.signed_entity_types | contains(["CardanoTransactions"])'
156
180
```
157
181
158
- For example with the aggregator on ` testing-sanchonet ` Mithril network:
182
+ For example with the aggregator on ` pre-release-preview ` Mithril network:
159
183
160
184
``` bash
161
- wget -q -O - https://aggregator.testing-sanchonet .api.mithril.network/aggregator | jq ' .capabilities.signed_entity_types | contains(["CardanoTransactions"])'
185
+ wget -q -O - https://aggregator.pre-release-preview .api.mithril.network/aggregator | jq ' .capabilities.signed_entity_types | contains(["CardanoTransactions"])'
162
186
```
163
187
164
188
:::
165
189
166
190
``` js
167
- const proof = await client .unstable . get_cardano_transaction_proofs ([
191
+ const proof = await client .get_cardano_transaction_proofs ([
168
192
" CARDANO_TRANSACTION_HASH_1" ,
169
193
" CARDANO_TRANSACTION_HASH_2" ,
170
194
]);
@@ -180,7 +204,7 @@ console.log(
180
204
);
181
205
182
206
let valid_cardano_transaction_proof =
183
- await client .unstable . verify_cardano_transaction_proof_then_compute_message (
207
+ await client .verify_cardano_transaction_proof_then_compute_message (
184
208
proof,
185
209
proof_certificate,
186
210
);
@@ -190,8 +214,68 @@ console.log(
190
214
);
191
215
```
192
216
217
+ With the same logic as above, if the aggregator signs ** CardanoStakeDistribution** , you can add the code below to the previous example:
218
+
193
219
::: tip
194
220
195
- You can read the complete [ Rust developer documentation] ( https://mithril.network/rust-doc/mithril_client_wasm/index.html ) .
221
+ You can verify that the aggregator signs ** CardanoStakeDistribution** by running the command below:
222
+
223
+ ``` bash
224
+ wget -q -O - YOUR_AGGREGATOR_ENDPOINT | jq ' .capabilities.signed_entity_types | contains(["CardanoStakeDistribution"])'
225
+ ```
226
+
227
+ For example with the aggregator on ` testing-preview ` Mithril network:
228
+
229
+ ``` bash
230
+ wget -q -O - https://aggregator.testing-preview.api.mithril.network/aggregator | jq ' .capabilities.signed_entity_types | contains(["CardanoStakeDistribution"])'
231
+ ```
196
232
197
233
:::
234
+
235
+ ``` js
236
+ let cardano_stake_distributions_list =
237
+ await client .list_cardano_stake_distributions ();
238
+ console .log (" cardano stake distributions:" , cardano_stake_distributions_list);
239
+
240
+ let last_cardano_stake_distribution =
241
+ await client .get_cardano_stake_distribution (
242
+ cardano_stake_distributions_list[0 ].hash ,
243
+ );
244
+ console .log (
245
+ " last_cardano_stake_distribution:" ,
246
+ last_cardano_stake_distribution,
247
+ );
248
+
249
+ let certificate = await client .get_mithril_certificate (
250
+ last_cardano_stake_distribution .certificate_hash ,
251
+ );
252
+ console .log (" certificate:" , certificate);
253
+
254
+ let last_certificate_from_chain = await client .verify_certificate_chain (
255
+ certificate .hash ,
256
+ );
257
+ console .log (
258
+ " verify certificate chain OK, last_certificate_from_chain:" ,
259
+ last_certificate_from_chain,
260
+ );
261
+
262
+ let cardano_stake_distribution_message =
263
+ await client .compute_cardano_stake_distribution_message (
264
+ certificate,
265
+ last_cardano_stake_distribution,
266
+ );
267
+ console .log (
268
+ " cardano_stake_distribution_message:" ,
269
+ cardano_stake_distribution_message,
270
+ );
271
+
272
+ let valid_cardano_stake_distribution_message =
273
+ await client .verify_message_match_certificate (
274
+ cardano_stake_distribution_message,
275
+ last_certificate_from_chain,
276
+ );
277
+ console .log (
278
+ " valid_cardano_stake_distribution_message:" ,
279
+ valid_cardano_stake_distribution_message,
280
+ );
281
+ ```
0 commit comments