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
use bab_rs::William3Hasher;
use ufotofu::BulkProducer;
use willow_data_model::entry::entry_builder;
use willow_data_model::prelude as wdm;
use crate::prelude::*;
wrapper! {
/// Builder for [`Entry`].
EntryBuilder<State: entry_builder::State = entry_builder::Empty>; wdm::EntryBuilder<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest, State>
}
impl<State: entry_builder::State> EntryBuilder<State> {
/// Sets the [namespace_id](https://willowprotocol.org/specs/data-model/index.html#entry_namespace_id) of the entry being built.
pub fn namespace_id(
self,
value: NamespaceId,
) -> EntryBuilder<entry_builder::SetNamespaceId<State>> {
self.0.namespace_id(value).into()
}
/// Sets the [subspace_id](https://willowprotocol.org/specs/data-model/index.html#entry_subspace_id) of the entry being built.
pub fn subspace_id(
self,
value: SubspaceId,
) -> EntryBuilder<entry_builder::SetSubspaceId<State>> {
self.0.subspace_id(value).into()
}
/// Sets the [path](https://willowprotocol.org/specs/data-model/index.html#entry_path) of the entry being built.
pub fn path(self, value: Path) -> EntryBuilder<entry_builder::SetPath<State>> {
self.0.path(value.into()).into()
}
/// Sets the [timestamp](https://willowprotocol.org/specs/data-model/index.html#entry_timestamp) of the entry being built.
pub fn timestamp<T: Into<Timestamp>>(
self,
value: T,
) -> EntryBuilder<entry_builder::SetTimestamp<State>> {
self.0.timestamp(value.into()).into()
}
/// Sets the [payload_length](https://willowprotocol.org/specs/data-model/index.html#entry_payload_length) of the entry being built.
pub fn payload_length(
self,
value: u64,
) -> EntryBuilder<entry_builder::SetPayloadLength<State>> {
self.0.payload_length(value).into()
}
/// Sets the [payload_digest](https://willowprotocol.org/specs/data-model/index.html#entry_payload_digest) of the entry being built.
pub fn payload_digest(
self,
value: PayloadDigest,
) -> EntryBuilder<entry_builder::SetPayloadDigest<State>> {
self.0.payload_digest(value).into()
}
/// Sets the [timestamp](https://willowprotocol.org/specs/data-model/index.html#entry_timestamp) of the entry being built to the current time.
///
/// ```
/// use willow25::prelude::*;
///
/// let entry = Entry::builder()
/// .now().unwrap()
/// .namespace_id([0; 32].into())
/// .subspace_id([1; 32].into())
/// .path(path!("/vacation/plan"))
/// .payload_digest([77; 32].into())
/// .payload_length(17)
/// .build();
///
/// assert!(entry.timestamp() > 814673376414009.into());
/// // 814673376414009 is the timestamp for 26.10.2025 afternoon-ish in Berlin.
/// ```
#[cfg(feature = "std")]
pub fn now(self) -> Result<EntryBuilder<entry_builder::SetTimestamp<State>>, HifitimeError> {
self.0.now().map(|b| b.into())
}
/// Sets the [payload_length](https://willowprotocol.org/specs/data-model/index.html#entry_payload_length) and [payload_digest](https://willowprotocol.org/specs/data-model/index.html#entry_payload_digest) of the entry being built to those of the given [Payload](https://willowprotocol.org/specs/data-model/index.html#Payload).
///
/// ```
/// use willow25::prelude::*;
///
/// let entry = Entry::builder()
/// .namespace_id([0; 32].into())
/// .subspace_id([1; 32].into())
/// .path(path!("/vacation/plan"))
/// .timestamp(12345)
/// .payload(b"See all the sights!")
/// .build();
///
/// assert_eq!(*entry.payload_digest(), [
/// 30, 72, 189, 217, 105, 47, 66, 151,
/// 107, 162, 70, 193, 110, 66, 169, 91,
/// 102, 134, 136, 3, 177, 198, 63, 147,
/// 147, 222, 117, 245, 149, 243, 155, 150,
/// ].into());
/// assert_eq!(entry.payload_length(), 19);
/// ```
pub fn payload<Payload: AsRef<[u8]>>(
self,
payload: Payload,
) -> EntryBuilder<entry_builder::SetPayloadLength<entry_builder::SetPayloadDigest<State>>> {
self.0
.payload::<Payload, William3Hasher, bab_rs::William3Digest>(payload)
.into()
}
/// Sets the [namespace_id](https://willowprotocol.org/specs/data-model/index.html#entry_namespace_id) of the entry being built to the [default_namespace_id](https://willowprotocol.org/specs/willow25/index.html#willow25_default_namespace_id).
pub fn default_namespace_id(self) -> EntryBuilder<entry_builder::SetNamespaceId<State>> {
self.namespace_id(crate::defaults::default_namespace_id())
}
/// Sets the [subspace_id](https://willowprotocol.org/specs/data-model/index.html#entry_subspace_id) of the entry being built to the [default_subspace_id](https://willowprotocol.org/specs/willow25/index.html#willow25_default_subspace_id).
pub fn default_subspace_id(self) -> EntryBuilder<entry_builder::SetSubspaceId<State>> {
self.subspace_id(crate::defaults::default_subspace_id())
}
/// Sets the [payload_digest](https://willowprotocol.org/specs/data-model/index.html#entry_payload_digest) and [payload_length](https://willowprotocol.org/specs/data-model/index.html#entry_payload_length) of the entry being built to the [default_payload_digest](https://willowprotocol.org/specs/confidential-sync/index.html#sync_default_payload_digest).
pub fn default_payload(
self,
) -> EntryBuilder<entry_builder::SetPayloadLength<entry_builder::SetPayloadDigest<State>>> {
self.payload_digest(crate::defaults::default_payload_digest())
.payload_length(crate::defaults::DEFAULT_PAYLOAD_LENGTH)
}
/// Sets the [payload_length](https://willowprotocol.org/specs/data-model/index.html#entry_payload_length) and [payload_digest](https://willowprotocol.org/specs/data-model/index.html#entry_payload_digest) of the entry being built to those of the payload given by the producer.
///
/// ```
/// use willow25::prelude::*;
/// use ufotofu::producer::clone_from_slice;
///
/// # pollster::block_on(async {
/// let mut producer = clone_from_slice(b"See all the sights!");
///
/// let entry = Entry::builder()
/// .namespace_id([0; 32].into())
/// .subspace_id([1; 32].into())
/// .path(path!("/vacation/plan"))
/// .timestamp(12345)
/// .payload_async(&mut producer).await.unwrap()
/// .build();
///
/// assert_eq!(*entry.payload_digest(), [
/// 30, 72, 189, 217, 105, 47, 66, 151,
/// 107, 162, 70, 193, 110, 66, 169, 91,
/// 102, 134, 136, 3, 177, 198, 63, 147,
/// 147, 222, 117, 245, 149, 243, 155, 150,
/// ].into());
/// assert_eq!(entry.payload_length(), 19);
/// # })
/// ```
pub async fn payload_async<P>(
self,
payload_producer: &mut P,
) -> Result<
EntryBuilder<entry_builder::SetPayloadLength<entry_builder::SetPayloadDigest<State>>>,
P::Error,
>
where
P: BulkProducer<Item = u8, Final = ()>,
{
self.0
.payload_async::<P, William3Hasher, bab_rs::William3Digest>(payload_producer)
.await
.map(|b| b.into())
}
/// Builds the [`Entry`].
pub fn build(self) -> Entry
where
State: entry_builder::IsComplete,
{
self.0.build().into()
}
}