Skip to main content

nym_api_requests/models/
directory.rs

1// Copyright 2026 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: GPL-3.0-only
3
4use crate::pagination::PaginatedResponse;
5use nym_crypto::asymmetric::ed25519;
6use nym_crypto::asymmetric::ed25519::bs58_ed25519_pubkey;
7use nym_directory_contract_common::DirectoryEntryRecord;
8use nym_mixnet_contract_common::NodeId;
9use serde::{Deserialize, Serialize};
10use serde_with::{DeserializeAs, SerializeAs};
11use std::collections::BTreeMap;
12use tendermint::block::Height;
13use utoipa::ToSchema;
14
15#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
16pub struct DirectoryEntriesRecordsResponse {
17    /// The height every entry (and identity) was pinned to - the same height the client
18    /// obtained a quorum'd snapshot for.
19    #[schema(value_type = String)]
20    pub height: Height,
21
22    pub entries: PaginatedResponse<DirectoryEntryRecord>,
23}
24
25#[serde_with::serde_as]
26#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
27pub struct DirectoryEntriesIdentitiesResponse {
28    /// The height every entry (and identity) was pinned to - the same height the client
29    /// obtained a quorum'd snapshot for.
30    #[schema(value_type = String)]
31    pub height: Height,
32
33    /// The `NodeId -> ed25519 identity` mapping, hashed into the snapshot's
34    /// `node_identities_hash` and used to attribute node-entry authorship.
35    #[serde_as(as = "BTreeMap<_, Ed25519PubKeySerde>")]
36    #[schema(value_type = std::collections::BTreeMap<u32, String>)]
37    pub node_identities: BTreeMap<NodeId, ed25519::PublicKey>,
38}
39
40struct Ed25519PubKeySerde;
41
42impl SerializeAs<ed25519::PublicKey> for Ed25519PubKeySerde {
43    fn serialize_as<S>(value: &ed25519::PublicKey, serializer: S) -> Result<S::Ok, S::Error>
44    where
45        S: serde::Serializer,
46    {
47        bs58_ed25519_pubkey::serialize(value, serializer)
48    }
49}
50
51impl<'de> DeserializeAs<'de, ed25519::PublicKey> for Ed25519PubKeySerde {
52    fn deserialize_as<D>(deserializer: D) -> Result<ed25519::PublicKey, D::Error>
53    where
54        D: serde::Deserializer<'de>,
55    {
56        bs58_ed25519_pubkey::deserialize(deserializer)
57    }
58}