ic-platform 0.34.9

Explicit IC certificate and authentication boundaries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
//! Explicit Ed25519 identity and original-request transport, with optional
//! externally signed direct secp256k1 admission. No discovery,
//! polling, renewal, redirect, proxy or retry is performed by these operations.
use super::{ReadClient, ReadError, TimePolicy, authenticate_certificate};
use crate::{
    ed25519::{Signature, Signer, SigningKey, VerifyingKey},
    ingress::{self, Content, Envelope},
};
use candidate_types::Principal;
use ed25519_dalek::pkcs8::DecodePrivateKey;
use ic_certification::LookupResult;
use serde::Serialize;

/// Explicit original update fields; construction performs no network activity.
#[derive(Clone, Copy, Debug)]
pub struct UpdateArgs<'a> {
    /// Signed destination, possibly the management canister.
    pub recipient: Principal,
    /// HTTP routing and certificate-authority target.
    pub effective: Principal,
    /// Exact method name.
    pub method: &'a str,
    /// Exact argument bytes.
    pub arg: &'a [u8],
    /// Original expiry in nanoseconds.
    pub expiry: u64,
    /// Optional nonce, preserving absence versus present empty bytes.
    pub nonce: Option<&'a [u8]>,
}
/// Caller-supplied Ed25519 key. It is never discovered or loaded from disk here.
/// Secret storage is zeroized by the upstream signing key on drop.
pub struct Ed25519Identity(SigningKey);
impl Ed25519Identity {
    /// Parse an explicit PKCS#8 Ed25519 PEM (BasicIdentity format), offline.
    /// # Errors
    /// Refuses PEM exceeding the inclusive bound, another algorithm or invalid key.
    pub fn from_pem(pem: &str, maximum_bytes: usize) -> Result<Self, ReadError> {
        if pem.len() > maximum_bytes {
            return Err(ReadError::ByteLimit);
        }
        SigningKey::from_pkcs8_pem(pem)
            .map(Self)
            .map_err(|_| ReadError::Packet)
    }
    fn public_key(&self) -> Vec<u8> {
        [
            b"\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00".as_slice(),
            &self.0.verifying_key().to_bytes(),
        ]
        .concat()
    }
    /// Offline canonical self-authenticating identity.
    #[must_use]
    pub fn principal(&self) -> Principal {
        Principal::self_authenticating(self.public_key())
    }
    fn envelope(&self, content: Content, maximum: usize) -> Result<Vec<u8>, ReadError> {
        let signature = self
            .0
            .sign(&content.signable().map_err(|_| ReadError::Packet)?);
        encode(
            &Envelope {
                content,
                sender_pubkey: Some(self.public_key()),
                sender_sig: Some(signature.to_bytes().to_vec()),
                sender_delegation: None,
            },
            maximum,
        )
    }
    /// Prepare an exact signed update offline, with explicit expiry and nonce.
    /// Recipient and effective routing target are intentionally distinct.
    /// # Errors
    /// Refuses oversized fields/envelope or packet/signing admission failure.
    pub fn prepare_update(
        &self,
        args: UpdateArgs<'_>,
        maximum_bytes: usize,
    ) -> Result<PreparedUpdate, ReadError> {
        let UpdateArgs {
            recipient,
            effective,
            method,
            arg,
            expiry,
            nonce,
        } = args;
        if method
            .len()
            .checked_add(arg.len())
            .and_then(|n| n.checked_add(nonce.map_or(0, <[u8]>::len)))
            .is_none_or(|n| n > maximum_bytes)
        {
            return Err(ReadError::ByteLimit);
        }
        let bytes = self.envelope(
            Content::Call {
                nonce: nonce.map(<[u8]>::to_vec),
                ingress_expiry: expiry,
                sender: self.principal(),
                canister_id: recipient,
                method_name: method.to_owned(),
                arg: arg.to_vec(),
                sender_info: None,
            },
            maximum_bytes,
        )?;
        PreparedUpdate::from_bytes(&bytes, effective, maximum_bytes)
    }
}
// Packet construction has one bounded serializer shared with ingress admission.
fn encode<T: Serialize>(value: &T, maximum: usize) -> Result<Vec<u8>, ReadError> {
    ingress::encode(value, maximum).map_err(|error| match error {
        ingress::EncodeError::ByteLimit | ingress::EncodeError::Allocation => ReadError::ByteLimit,
        ingress::EncodeError::Packet => ReadError::Packet,
    })
}
/// Immutable, signature-checked original update. Loading does not check expiry:
/// recovery must remain possible after the original ingress has expired.
#[derive(Debug)]
pub struct PreparedUpdate {
    bytes: Vec<u8>,
    id: [u8; 32],
    expiry: u64,
    sender: Principal,
    recipient: Principal,
    effective: Principal,
}
impl PreparedUpdate {
    /// Admit exact retained bytes from durable custody; never re-encode them.
    /// Direct Ed25519 is supported; `native-signed-secp256k1` also admits direct
    /// secp256k1. Caller admits effective routing.
    /// # Errors
    /// Refuses malformed/oversized envelopes, delegation, sender info, wrong sender
    /// binding, weak keys or invalid signatures. No freshness claim is made.
    pub fn from_bytes(
        bytes: &[u8],
        effective: Principal,
        maximum_bytes: usize,
    ) -> Result<Self, ReadError> {
        let envelope = ingress::decode_envelope(bytes, maximum_bytes)
            .map_err(|_| ReadError::Packet)?
            .value;
        let Content::Call {
            ingress_expiry,
            sender,
            canister_id,
            ref sender_info,
            ..
        } = envelope.content
        else {
            return Err(ReadError::Packet);
        };
        if envelope.sender_delegation.is_some() || sender_info.is_some() {
            return Err(ReadError::Packet);
        }
        verify_envelope(&envelope, sender)?;
        Ok(Self {
            bytes: bytes.to_vec(),
            id: envelope
                .content
                .request_id()
                .map_err(|_| ReadError::Packet)?,
            expiry: ingress_expiry,
            sender,
            recipient: canister_id,
            effective,
        })
    }
    /// Exact original envelope bytes, including original CBOR framing.
    #[must_use]
    pub fn envelope_bytes(&self) -> &[u8] {
        &self.bytes
    }
    /// Original representation-independent request identity.
    #[must_use]
    pub const fn request_id(&self) -> &[u8; 32] {
        &self.id
    }
    /// Original expiry, never renewed by observation.
    #[must_use]
    pub const fn expiry(&self) -> u64 {
        self.expiry
    }
    /// Signed sender identity.
    #[must_use]
    pub const fn sender(&self) -> Principal {
        self.sender
    }
    /// Signed recipient (possibly the management canister).
    #[must_use]
    pub const fn recipient(&self) -> Principal {
        self.recipient
    }
    /// Explicit HTTP route and certificate authority target.
    #[must_use]
    pub const fn effective_canister(&self) -> Principal {
        self.effective
    }
}
// Strict direct-key profiles; cryptographic verification remains upstream.
fn verify_envelope(envelope: &Envelope, sender: Principal) -> Result<(), ReadError> {
    if envelope.sender_delegation.is_some() {
        return Err(ReadError::Packet);
    }
    let public = envelope.sender_pubkey.as_deref().ok_or(ReadError::Packet)?;
    if Principal::self_authenticating(public) != sender {
        return Err(ReadError::Packet);
    }
    let signature = envelope.sender_sig.as_deref().ok_or(ReadError::Packet)?;
    let message = envelope.content.signable().map_err(|_| ReadError::Packet)?;
    if let Some(raw) = public.strip_prefix(b"\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00") {
        let raw = raw.try_into().map_err(|_| ReadError::Packet)?;
        let key = VerifyingKey::from_bytes(raw).map_err(|_| ReadError::Packet)?;
        if key.is_weak() {
            return Err(ReadError::Packet);
        }
        return key
            .verify_strict(
                &message,
                &Signature::from_slice(signature).map_err(|_| ReadError::Packet)?,
            )
            .map_err(|_| ReadError::Packet);
    }
    #[cfg(feature = "native-signed-secp256k1")]
    if let Some(raw) = public.strip_prefix(b"\x30\x56\x30\x10\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x05\x2b\x81\x04\x00\x0a\x03\x42\x00") {
        use k256::ecdsa::{Signature, VerifyingKey, signature::Verifier};
        if raw.len() != 65 || raw[0] != 4 { return Err(ReadError::Packet); }
        let key = VerifyingKey::from_sec1_bytes(raw).map_err(|_| ReadError::Packet)?;
        let signature = Signature::from_slice(signature).map_err(|_| ReadError::Packet)?;
        return key.verify(&message, &signature).map_err(|_| ReadError::Packet);
    }
    Err(ReadError::Packet)
}

/// Signature-checked externally prepared status read for one original update.
/// No key custody, expiry renewal or network operation occurs on admission.
#[derive(Debug)]
pub struct PreparedRequestStatus {
    bytes: Vec<u8>,
    id: [u8; 32],
    sender: Principal,
    effective: Principal,
    expiry: u64,
}
impl PreparedRequestStatus {
    /// Admit exactly one request-status path bound to this update and sender.
    /// Preserves the original read expiry without imposing current-time policy.
    /// A freshly authorized read is an explicit caller decision, never automatic.
    /// # Errors
    /// Refuses malformed, oversized, delegated, unsupported-key or incorrectly
    /// signed envelopes, wrong senders, extra paths and mismatched request IDs.
    pub fn from_bytes(
        bytes: &[u8],
        update: &PreparedUpdate,
        maximum_bytes: usize,
    ) -> Result<Self, ReadError> {
        let envelope = ingress::decode_envelope(bytes, maximum_bytes)
            .map_err(|_| ReadError::Packet)?
            .value;
        let Content::ReadState {
            sender,
            ingress_expiry,
            ref paths,
        } = envelope.content
        else {
            return Err(ReadError::Packet);
        };
        if sender != update.sender
            || paths.len() != 1
            || paths[0].len() != 2
            || paths[0][0] != b"request_status"
            || paths[0][1] != update.id
        {
            return Err(ReadError::Packet);
        }
        verify_envelope(&envelope, sender)?;
        Ok(Self {
            bytes: bytes.to_vec(),
            id: update.id,
            sender,
            effective: update.effective,
            expiry: ingress_expiry,
        })
    }
    /// Exact retained signed read-state envelope, without re-encoding.
    #[must_use]
    pub fn envelope_bytes(&self) -> &[u8] {
        &self.bytes
    }
    /// Explicit expiry of this read authorization, independent of update expiry.
    #[must_use]
    pub const fn expiry(&self) -> u64 {
        self.expiry
    }
}

/// Certified observation of exactly the original request. Absence and pruning
/// are not evidence of nonexecution and never authorize replacement submission.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum RequestStatus {
    /// Certified `received` state.
    Received,
    /// Certified `processing` state.
    Processing,
    /// Certified exact reply bytes.
    Replied(Vec<u8>),
    /// Certified rejection with raw numeric code and diagnostic text.
    Rejected {
        /// Raw source code.
        code: u64,
        /// Exact message.
        message: String,
        /// Optional exact source error code.
        error_code: Option<String>,
    },
    /// Certified terminal marker; reply has been pruned.
    Done,
    /// Certified absence of the selected request status.
    Unknown,
    /// The witness does not reveal the selected path.
    Unavailable,
}
/// Immutable verified status with the original certificate and request binding.
#[derive(Debug)]
pub struct RequestObservation {
    certificate: Vec<u8>,
    id: [u8; 32],
    effective: Principal,
    time_ns: u64,
    status: RequestStatus,
}
impl RequestObservation {
    /// Exact proof bytes, retained without re-encoding.
    #[must_use]
    pub fn certificate_bytes(&self) -> &[u8] {
        &self.certificate
    }
    /// Original request selected by this observation.
    #[must_use]
    pub const fn request_id(&self) -> &[u8; 32] {
        &self.id
    }
    /// Authenticated effective target.
    #[must_use]
    pub const fn effective_canister(&self) -> Principal {
        self.effective
    }
    /// Certified observation time.
    #[must_use]
    pub const fn time_ns(&self) -> u64 {
        self.time_ns
    }
    /// Authenticated selected outcome.
    #[must_use]
    pub const fn status(&self) -> &RequestStatus {
        &self.status
    }
}
/// Dispatch response. An error from dispatch is delivery uncertainty, never
/// evidence that the original request was not executed.
#[derive(Debug)]
pub enum Dispatch {
    /// Accepted without completion evidence.
    Accepted,
    /// Authenticated original-request observation.
    Observed(RequestObservation),
    /// Uncertified boundary-node rejection; not an executed certified rejection.
    UncertifiedRejection {
        /// Raw numeric code.
        code: u64,
        /// Exact diagnostic.
        message: String,
        /// Optional exact error code.
        error_code: Option<String>,
    },
}
impl ReadClient {
    /// Send the retained original bytes exactly once. No redirect/retry/polling.
    /// Caller owns custody, expiry admission and any later observation policy.
    /// # Errors
    /// Every transport/status/packet/proof refusal leaves delivery uncertain.
    pub async fn dispatch(
        &self,
        update: &PreparedUpdate,
        time: TimePolicy,
    ) -> Result<Dispatch, ReadError> {
        if update.bytes.len() > self.config.message_bytes {
            return Err(ReadError::ByteLimit);
        }
        let (status, bytes) = self
            .post_response(
                &format!("api/v3/canister/{}/call", update.effective),
                update.bytes.clone(),
            )
            .await?;
        if bytes.is_empty() && status == reqwest::StatusCode::ACCEPTED {
            return Ok(Dispatch::Accepted);
        }
        match ingress::decode_call_response(&bytes, self.config.message_bytes)
            .map_err(|_| ReadError::Packet)?
            .value
        {
            ingress::CallResponse::Accepted => Ok(Dispatch::Accepted),
            ingress::CallResponse::Replied { certificate } => self
                .authenticate_request(update, &certificate, time)
                .map(Dispatch::Observed),
            ingress::CallResponse::NonReplicatedRejection {
                reject_code,
                reject_message,
                error_code,
            } => Ok(Dispatch::UncertifiedRejection {
                code: reject_code,
                message: reject_message,
                error_code,
            }),
        }
    }
    /// Observe the original ID once using a newly signed read-state request.
    /// `read_expiry` applies only to that read; the update is never renewed/sent.
    /// `time` admits current network evidence independently of original expiry.
    /// # Errors
    /// Refuses wrong identity, transport or certificate admission failures.
    pub async fn observe_request(
        &self,
        identity: &Ed25519Identity,
        update: &PreparedUpdate,
        read_expiry: u64,
        time: TimePolicy,
    ) -> Result<RequestObservation, ReadError> {
        if identity.principal() != update.sender {
            return Err(ReadError::Packet);
        }
        let body = identity.envelope(
            Content::ReadState {
                ingress_expiry: read_expiry,
                sender: update.sender,
                paths: vec![
                    vec![b"request_status".to_vec(), update.id.to_vec()],
                    vec![b"time".to_vec()],
                ],
            },
            self.config.message_bytes,
        )?;
        let bytes = self
            .post_bytes(
                &format!("api/v3/canister/{}/read_state", update.effective),
                body,
            )
            .await?;
        let response = ingress::decode_read_state_response(&bytes, self.config.message_bytes)
            .map_err(|_| ReadError::Packet)?;
        self.authenticate_request(update, &response.value.certificate, time)
    }
    /// Send an externally signed status read exactly once, without replacing it.
    /// Fresh authorization, expiry admission and subsequent reads remain caller-owned.
    /// Only the supplied original request is observed; this never dispatches it.
    /// # Errors
    /// Refuses changed request/sender/effective bindings, transport or proof failures.
    /// Failure does not establish that the original update was not executed.
    pub async fn observe_prepared_request(
        &self,
        update: &PreparedUpdate,
        status: &PreparedRequestStatus,
        time: TimePolicy,
    ) -> Result<RequestObservation, ReadError> {
        if status.bytes.len() > self.config.message_bytes {
            return Err(ReadError::ByteLimit);
        }
        if status.id != update.id
            || status.sender != update.sender
            || status.effective != update.effective
        {
            return Err(ReadError::Packet);
        }
        let bytes = self
            .post_bytes(
                &format!("api/v3/canister/{}/read_state", status.effective),
                status.bytes.clone(),
            )
            .await?;
        let response = ingress::decode_read_state_response(&bytes, self.config.message_bytes)
            .map_err(|_| ReadError::Packet)?;
        self.authenticate_request(update, &response.value.certificate, time)
    }
    /// Replay an original proof offline under explicitly selected historical
    /// certificate/delegation time windows. No current-network freshness inferred.
    /// # Errors
    /// Refuses wrong authority/root, malformed proofs or selected status leaves.
    pub fn authenticate_request(
        &self,
        update: &PreparedUpdate,
        certificate: &[u8],
        time: TimePolicy,
    ) -> Result<RequestObservation, ReadError> {
        let evidence = authenticate_certificate(
            self.decode(certificate)?,
            &self.config.root,
            update.effective,
            time,
            self.config.verification,
        )?;
        let tree = evidence.tree();
        let lookup = |name: &[u8]| {
            tree.lookup_path([b"request_status".as_slice(), update.id.as_slice(), name])
        };
        let required = |name: &[u8]| match lookup(name) {
            LookupResult::Found(bytes) => Ok(bytes),
            _ => Err(ReadError::MissingPath),
        };
        let text = |name: &[u8]| {
            std::str::from_utf8(required(name)?)
                .map(str::to_owned)
                .map_err(|_| ReadError::Packet)
        };
        let status = match lookup(b"status") {
            LookupResult::Absent => RequestStatus::Unknown,
            LookupResult::Unknown => RequestStatus::Unavailable,
            LookupResult::Error => return Err(ReadError::Packet),
            LookupResult::Found(status) => match status {
                b"received" => RequestStatus::Received,
                b"processing" => RequestStatus::Processing,
                b"done" => RequestStatus::Done,
                b"replied" => RequestStatus::Replied(required(b"reply")?.to_vec()),
                b"rejected" => RequestStatus::Rejected {
                    code: unsigned(required(b"reject_code")?)?,
                    message: text(b"reject_message")?,
                    error_code: match lookup(b"error_code") {
                        LookupResult::Absent => None,
                        LookupResult::Found(value) => Some(
                            std::str::from_utf8(value)
                                .map_err(|_| ReadError::Packet)?
                                .to_owned(),
                        ),
                        _ => return Err(ReadError::MissingPath),
                    },
                },
                _ => return Err(ReadError::Packet),
            },
        };
        Ok(RequestObservation {
            certificate: certificate.to_vec(),
            id: update.id,
            effective: update.effective,
            time_ns: evidence.time_ns(),
            status,
        })
    }
    /// Execute one explicitly signed query and authenticate its node signatures
    /// through the existing certified node-key/routing path. Caller bounds the
    /// whole operation in addition to the configured per-request timeout.
    /// # Errors
    /// Refuses oversized requests, transport, node authority/signature/time failures.
    pub async fn signed_query(
        &self,
        identity: &Ed25519Identity,
        canister: Principal,
        method: &str,
        args: &[u8],
        expiry: u64,
        time: TimePolicy,
    ) -> Result<Vec<u8>, ReadError> {
        if args
            .len()
            .checked_add(method.len())
            .is_none_or(|n| n > self.config.message_bytes)
        {
            return Err(ReadError::ByteLimit);
        }
        let content = ic_transport_types::EnvelopeContent::Query {
            sender: identity
                .principal()
                .to_string()
                .parse()
                .map_err(|_| ReadError::Packet)?,
            canister_id: canister
                .to_string()
                .parse()
                .map_err(|_| ReadError::Packet)?,
            ingress_expiry: expiry,
            method_name: method.to_owned(),
            arg: args.to_vec(),
            nonce: None,
            sender_info: None,
        };
        let id = ic_transport_types::to_request_id(&content).map_err(|_| ReadError::Packet)?;
        let envelope = ic_transport_types::Envelope {
            content: std::borrow::Cow::Borrowed(&content),
            sender_pubkey: Some(identity.public_key()),
            sender_sig: Some(identity.0.sign(&id.signable()).to_bytes().to_vec()),
            sender_delegation: None,
        };
        self.query_content(
            canister,
            &content,
            expiry,
            time,
            Some(encode(&envelope, self.config.message_bytes)?),
        )
        .await
    }
}
fn unsigned(bytes: &[u8]) -> Result<u64, ReadError> {
    let mut value = 0;
    for (index, byte) in bytes.iter().copied().enumerate() {
        if index > 9 || (index == 9 && byte > 1) {
            return Err(ReadError::Packet);
        }
        value |= u64::from(byte & 127) << (index * 7);
        if byte & 128 == 0 {
            return if index + 1 == bytes.len() {
                Ok(value)
            } else {
                Err(ReadError::Packet)
            };
        }
    }
    Err(ReadError::Packet)
}

impl ReadClient {
    /// Read and authenticate the exact installed module hash. This observation
    /// is not atomic with a later application call or an upgrade authorization.
    /// # Errors
    /// Refuses transport, authority/time failures, absent/pruned or non-32-byte hash.
    pub async fn canister_module_hash(
        &self,
        canister: Principal,
        expiry: u64,
        time: TimePolicy,
    ) -> Result<[u8; 32], ReadError> {
        let bytes = self
            .state(
                "canister",
                canister,
                vec![
                    vec![
                        b"canister".to_vec(),
                        canister.as_slice().to_vec(),
                        b"module_hash".to_vec(),
                    ],
                    vec![b"time".to_vec()],
                ],
                expiry,
            )
            .await?;
        let evidence = authenticate_certificate(
            self.decode(&bytes)?,
            &self.config.root,
            canister,
            time,
            self.config.verification,
        )?;
        match evidence.tree().lookup_path([
            b"canister".as_slice(),
            canister.as_slice(),
            b"module_hash".as_slice(),
        ]) {
            LookupResult::Found(hash) => hash.try_into().map_err(|_| ReadError::Packet),
            _ => Err(ReadError::MissingPath),
        }
    }
}