trust-tasks-rs 0.2.2

Reference Rust library for the Trust Tasks framework — transport-agnostic, JSON-based descriptions of verifiable work between parties.
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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `chat/message`. Version: `1.0`.
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
    /// Error from a `TryFrom` or `FromStr` implementation.
    pub struct ConversionError(::std::borrow::Cow<'static, str>);
    impl ::std::error::Error for ConversionError {}
    impl ::std::fmt::Display for ConversionError {
        fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
            ::std::fmt::Display::fmt(&self.0, f)
        }
    }
    impl ::std::fmt::Debug for ConversionError {
        fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
            ::std::fmt::Debug::fmt(&self.0, f)
        }
    }
    impl From<&'static str> for ConversionError {
        fn from(value: &'static str) -> Self {
            Self(value.into())
        }
    }
    impl From<String> for ConversionError {
        fn from(value: String) -> Self {
            Self(value.into())
        }
    }
}
///`AttachmentRef`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "type": "object",
///  "required": [
///    "id",
///    "mediaType"
///  ],
///  "properties": {
///    "digest": {
///      "description": "OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.",
///      "type": "string",
///      "minLength": 1
///    },
///    "filename": {
///      "description": "OPTIONAL. Suggested filename.",
///      "type": "string"
///    },
///    "id": {
///      "description": "Opaque attachment id, resolvable via the bridge's attachment fetch.",
///      "type": "string",
///      "minLength": 1
///    },
///    "mediaType": {
///      "description": "IANA media type (e.g. `image/jpeg`).",
///      "type": "string",
///      "minLength": 1
///    },
///    "sizeBytes": {
///      "description": "OPTIONAL. Size in bytes, if known ahead of fetch.",
///      "type": "integer",
///      "minimum": 0.0
///    }
///  },
///  "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct AttachmentRef {
    ///OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.
    #[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
    pub digest: ::std::option::Option<AttachmentRefDigest>,
    ///OPTIONAL. Suggested filename.
    #[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
    pub filename: ::std::option::Option<::std::string::String>,
    ///Opaque attachment id, resolvable via the bridge's attachment fetch.
    pub id: AttachmentRefId,
    ///IANA media type (e.g. `image/jpeg`).
    #[serde(rename = "mediaType")]
    pub media_type: AttachmentRefMediaType,
    ///OPTIONAL. Size in bytes, if known ahead of fetch.
    #[serde(
        rename = "sizeBytes",
        default,
        skip_serializing_if = "::std::option::Option::is_none"
    )]
    pub size_bytes: ::std::option::Option<u64>,
}
///OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.",
///  "type": "string",
///  "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct AttachmentRefDigest(::std::string::String);
impl ::std::ops::Deref for AttachmentRefDigest {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<AttachmentRefDigest> for ::std::string::String {
    fn from(value: AttachmentRefDigest) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for AttachmentRefDigest {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        if value.chars().count() < 1usize {
            return Err("shorter than 1 characters".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for AttachmentRefDigest {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for AttachmentRefDigest {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for AttachmentRefDigest {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for AttachmentRefDigest {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
///Opaque attachment id, resolvable via the bridge's attachment fetch.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "Opaque attachment id, resolvable via the bridge's attachment fetch.",
///  "type": "string",
///  "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct AttachmentRefId(::std::string::String);
impl ::std::ops::Deref for AttachmentRefId {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<AttachmentRefId> for ::std::string::String {
    fn from(value: AttachmentRefId) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for AttachmentRefId {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        if value.chars().count() < 1usize {
            return Err("shorter than 1 characters".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for AttachmentRefId {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for AttachmentRefId {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for AttachmentRefId {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for AttachmentRefId {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
///IANA media type (e.g. `image/jpeg`).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "IANA media type (e.g. `image/jpeg`).",
///  "type": "string",
///  "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct AttachmentRefMediaType(::std::string::String);
impl ::std::ops::Deref for AttachmentRefMediaType {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<AttachmentRefMediaType> for ::std::string::String {
    fn from(value: AttachmentRefMediaType) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for AttachmentRefMediaType {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        if value.chars().count() < 1usize {
            return Err("shorter than 1 characters".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for AttachmentRefMediaType {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for AttachmentRefMediaType {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for AttachmentRefMediaType {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for AttachmentRefMediaType {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
///`ChainLink`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "type": "object",
///  "required": [
///    "digest",
///    "id"
///  ],
///  "properties": {
///    "digest": {
///      "description": "Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.",
///      "type": "string",
///      "minLength": 1
///    },
///    "id": {
///      "description": "The `id` of the previous `chat/message` Trust Task document in this conversation.",
///      "type": "string",
///      "minLength": 1
///    }
///  },
///  "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct ChainLink {
    ///Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.
    pub digest: ChainLinkDigest,
    ///The `id` of the previous `chat/message` Trust Task document in this conversation.
    pub id: ChainLinkId,
}
///Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.",
///  "type": "string",
///  "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ChainLinkDigest(::std::string::String);
impl ::std::ops::Deref for ChainLinkDigest {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<ChainLinkDigest> for ::std::string::String {
    fn from(value: ChainLinkDigest) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for ChainLinkDigest {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        if value.chars().count() < 1usize {
            return Err("shorter than 1 characters".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for ChainLinkDigest {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for ChainLinkDigest {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for ChainLinkDigest {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for ChainLinkDigest {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
///The `id` of the previous `chat/message` Trust Task document in this conversation.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "The `id` of the previous `chat/message` Trust Task document in this conversation.",
///  "type": "string",
///  "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ChainLinkId(::std::string::String);
impl ::std::ops::Deref for ChainLinkId {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<ChainLinkId> for ::std::string::String {
    fn from(value: ChainLinkId) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for ChainLinkId {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        if value.chars().count() < 1usize {
            return Err("shorter than 1 characters".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for ChainLinkId {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for ChainLinkId {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for ChainLinkId {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for ChainLinkId {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "title": "Ext",
///  "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
///  "type": "object",
///  "minProperties": 1,
///  "additionalProperties": true,
///  "propertyNames": {
///    "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///  }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
    type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
    fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
        &self.0
    }
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
    fn from(value: Ext) -> Self {
        value.0
    }
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
    fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
        Self(value)
    }
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "type": "string",
///  "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
    fn from(value: ExtKey) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for ExtKey {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
            ::std::sync::LazyLock::new(|| {
                ::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
            });
        if PATTERN.find(value).is_none() {
            return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for ExtKey {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
///A conversational message exchanged between an AI agent and a messaging-platform bridge. Signed by its author (via the document `proof`) and hash-linked to the previous message in the conversation (`prev`), so a third party can verify each message's author and ordering after the transport has closed — for audit and dispute resolution. Conversations and contacts are referenced by opaque, bridge-issued handles, never raw platform addresses.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "$id": "https://trusttasks.org/spec/chat/message/1.0",
///  "title": "Payload",
///  "description": "A conversational message exchanged between an AI agent and a messaging-platform bridge. Signed by its author (via the document `proof`) and hash-linked to the previous message in the conversation (`prev`), so a third party can verify each message's author and ordering after the transport has closed — for audit and dispute resolution. Conversations and contacts are referenced by opaque, bridge-issued handles, never raw platform addresses.",
///  "type": "object",
///  "required": [
///    "conversationId",
///    "direction",
///    "sentAt"
///  ],
///  "properties": {
///    "attachments": {
///      "description": "OPTIONAL. Attachments carried by reference, never inline.",
///      "type": "array",
///      "items": {
///        "$ref": "#/definitions/AttachmentRef"
///      }
///    },
///    "conversationId": {
///      "description": "Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).",
///      "type": "string",
///      "minLength": 1
///    },
///    "direction": {
///      "description": "`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).",
///      "type": "string",
///      "enum": [
///        "inbound",
///        "outbound"
///      ]
///    },
///    "ext": {
///      "$ref": "#/definitions/Ext"
///    },
///    "platform": {
///      "description": "OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.",
///      "type": "string",
///      "minLength": 1
///    },
///    "prev": {
///      "description": "OPTIONAL on the first message in a conversation; present on every message thereafter. Links to the previous message so the conversation forms a verifiable, ordered chain.",
///      "$ref": "#/definitions/ChainLink"
///    },
///    "replyToId": {
///      "description": "OPTIONAL. The `id` of the message this one replies to.",
///      "type": "string",
///      "minLength": 1
///    },
///    "sentAt": {
///      "description": "RFC 3339 timestamp the author asserts for this message.",
///      "type": "string",
///      "format": "date-time"
///    },
///    "text": {
///      "description": "OPTIONAL. Plain-text body. Absent for attachment-only messages.",
///      "type": "string"
///    }
///  },
///  "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct Payload {
    ///OPTIONAL. Attachments carried by reference, never inline.
    #[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
    pub attachments: ::std::vec::Vec<AttachmentRef>,
    ///Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).
    #[serde(rename = "conversationId")]
    pub conversation_id: PayloadConversationId,
    ///`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).
    pub direction: PayloadDirection,
    #[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
    pub ext: ::std::option::Option<Ext>,
    ///OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.
    #[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
    pub platform: ::std::option::Option<PayloadPlatform>,
    ///OPTIONAL on the first message in a conversation; present on every message thereafter. Links to the previous message so the conversation forms a verifiable, ordered chain.
    #[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
    pub prev: ::std::option::Option<ChainLink>,
    ///OPTIONAL. The `id` of the message this one replies to.
    #[serde(
        rename = "replyToId",
        default,
        skip_serializing_if = "::std::option::Option::is_none"
    )]
    pub reply_to_id: ::std::option::Option<PayloadReplyToId>,
    ///RFC 3339 timestamp the author asserts for this message.
    #[serde(rename = "sentAt")]
    pub sent_at: ::chrono::DateTime<::chrono::offset::Utc>,
    ///OPTIONAL. Plain-text body. Absent for attachment-only messages.
    #[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
    pub text: ::std::option::Option<::std::string::String>,
}
///Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).",
///  "type": "string",
///  "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadConversationId(::std::string::String);
impl ::std::ops::Deref for PayloadConversationId {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<PayloadConversationId> for ::std::string::String {
    fn from(value: PayloadConversationId) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for PayloadConversationId {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        if value.chars().count() < 1usize {
            return Err("shorter than 1 characters".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for PayloadConversationId {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadConversationId {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadConversationId {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for PayloadConversationId {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
///`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).",
///  "type": "string",
///  "enum": [
///    "inbound",
///    "outbound"
///  ]
///}
/// ```
/// </details>
#[derive(
    ::serde::Deserialize,
    ::serde::Serialize,
    Clone,
    Copy,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
)]
pub enum PayloadDirection {
    #[serde(rename = "inbound")]
    Inbound,
    #[serde(rename = "outbound")]
    Outbound,
}
impl ::std::fmt::Display for PayloadDirection {
    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
        match *self {
            Self::Inbound => f.write_str("inbound"),
            Self::Outbound => f.write_str("outbound"),
        }
    }
}
impl ::std::str::FromStr for PayloadDirection {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        match value {
            "inbound" => Ok(Self::Inbound),
            "outbound" => Ok(Self::Outbound),
            _ => Err("invalid value".into()),
        }
    }
}
impl ::std::convert::TryFrom<&str> for PayloadDirection {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadDirection {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadDirection {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
///OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.",
///  "type": "string",
///  "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadPlatform(::std::string::String);
impl ::std::ops::Deref for PayloadPlatform {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<PayloadPlatform> for ::std::string::String {
    fn from(value: PayloadPlatform) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for PayloadPlatform {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        if value.chars().count() < 1usize {
            return Err("shorter than 1 characters".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for PayloadPlatform {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadPlatform {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadPlatform {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for PayloadPlatform {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
///OPTIONAL. The `id` of the message this one replies to.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
///  "description": "OPTIONAL. The `id` of the message this one replies to.",
///  "type": "string",
///  "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadReplyToId(::std::string::String);
impl ::std::ops::Deref for PayloadReplyToId {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        &self.0
    }
}
impl ::std::convert::From<PayloadReplyToId> for ::std::string::String {
    fn from(value: PayloadReplyToId) -> Self {
        value.0
    }
}
impl ::std::str::FromStr for PayloadReplyToId {
    type Err = self::error::ConversionError;
    fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        if value.chars().count() < 1usize {
            return Err("shorter than 1 characters".into());
        }
        Ok(Self(value.to_string()))
    }
}
impl ::std::convert::TryFrom<&str> for PayloadReplyToId {
    type Error = self::error::ConversionError;
    fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadReplyToId {
    type Error = self::error::ConversionError;
    fn try_from(
        value: &::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadReplyToId {
    type Error = self::error::ConversionError;
    fn try_from(
        value: ::std::string::String,
    ) -> ::std::result::Result<Self, self::error::ConversionError> {
        value.parse()
    }
}
impl<'de> ::serde::Deserialize<'de> for PayloadReplyToId {
    fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
    where
        D: ::serde::Deserializer<'de>,
    {
        ::std::string::String::deserialize(deserializer)?
            .parse()
            .map_err(|e: self::error::ConversionError| {
                <D::Error as ::serde::de::Error>::custom(e.to_string())
            })
    }
}
impl crate::Payload for Payload {
    const TYPE_URI: &'static str = "https://trusttasks.org/spec/chat/message/1.0";
    const IS_PROOF_REQUIRED: bool = true;
    const IS_RECIPIENT_REQUIRED: bool = true;
}
#[cfg(feature = "validate")]
impl crate::validate::ValidatedPayload for Payload {
    const SCHEMA_JSON: &'static str = "{\n  \"$defs\": {\n    \"AttachmentRef\": {\n      \"additionalProperties\": false,\n      \"properties\": {\n        \"digest\": {\n          \"description\": \"OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.\",\n          \"minLength\": 1,\n          \"type\": \"string\"\n        },\n        \"filename\": {\n          \"description\": \"OPTIONAL. Suggested filename.\",\n          \"type\": \"string\"\n        },\n        \"id\": {\n          \"description\": \"Opaque attachment id, resolvable via the bridge's attachment fetch.\",\n          \"minLength\": 1,\n          \"type\": \"string\"\n        },\n        \"mediaType\": {\n          \"description\": \"IANA media type (e.g. `image/jpeg`).\",\n          \"minLength\": 1,\n          \"type\": \"string\"\n        },\n        \"sizeBytes\": {\n          \"description\": \"OPTIONAL. Size in bytes, if known ahead of fetch.\",\n          \"minimum\": 0,\n          \"type\": \"integer\"\n        }\n      },\n      \"required\": [\n        \"id\",\n        \"mediaType\"\n      ],\n      \"type\": \"object\"\n    },\n    \"ChainLink\": {\n      \"additionalProperties\": false,\n      \"properties\": {\n        \"digest\": {\n          \"description\": \"Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.\",\n          \"minLength\": 1,\n          \"type\": \"string\"\n        },\n        \"id\": {\n          \"description\": \"The `id` of the previous `chat/message` Trust Task document in this conversation.\",\n          \"minLength\": 1,\n          \"type\": \"string\"\n        }\n      },\n      \"required\": [\n        \"id\",\n        \"digest\"\n      ],\n      \"type\": \"object\"\n    },\n    \"Ext\": {\n      \"additionalProperties\": true,\n      \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n      \"minProperties\": 1,\n      \"propertyNames\": {\n        \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n      },\n      \"title\": \"Ext\",\n      \"type\": \"object\"\n    }\n  },\n  \"$id\": \"https://trusttasks.org/spec/chat/message/1.0\",\n  \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n  \"additionalProperties\": false,\n  \"description\": \"A conversational message exchanged between an AI agent and a messaging-platform bridge. Signed by its author (via the document `proof`) and hash-linked to the previous message in the conversation (`prev`), so a third party can verify each message's author and ordering after the transport has closed — for audit and dispute resolution. Conversations and contacts are referenced by opaque, bridge-issued handles, never raw platform addresses.\",\n  \"properties\": {\n    \"attachments\": {\n      \"description\": \"OPTIONAL. Attachments carried by reference, never inline.\",\n      \"items\": {\n        \"$ref\": \"#/$defs/AttachmentRef\"\n      },\n      \"type\": \"array\"\n    },\n    \"conversationId\": {\n      \"description\": \"Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).\",\n      \"minLength\": 1,\n      \"type\": \"string\"\n    },\n    \"direction\": {\n      \"description\": \"`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).\",\n      \"enum\": [\n        \"inbound\",\n        \"outbound\"\n      ],\n      \"type\": \"string\"\n    },\n    \"ext\": {\n      \"$ref\": \"#/$defs/Ext\"\n    },\n    \"platform\": {\n      \"description\": \"OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.\",\n      \"minLength\": 1,\n      \"type\": \"string\"\n    },\n    \"prev\": {\n      \"$ref\": \"#/$defs/ChainLink\",\n      \"description\": \"OPTIONAL on the first message in a conversation; present on every message thereafter. Links to the previous message so the conversation forms a verifiable, ordered chain.\"\n    },\n    \"replyToId\": {\n      \"description\": \"OPTIONAL. The `id` of the message this one replies to.\",\n      \"minLength\": 1,\n      \"type\": \"string\"\n    },\n    \"sentAt\": {\n      \"description\": \"RFC 3339 timestamp the author asserts for this message.\",\n      \"format\": \"date-time\",\n      \"type\": \"string\"\n    },\n    \"text\": {\n      \"description\": \"OPTIONAL. Plain-text body. Absent for attachment-only messages.\",\n      \"type\": \"string\"\n    }\n  },\n  \"required\": [\n    \"conversationId\",\n    \"direction\",\n    \"sentAt\"\n  ],\n  \"title\": \"Chat Message — payload\",\n  \"type\": \"object\"\n}\n";
}
#[cfg(test)]
mod conformance {
    //! Round-trip tests harvested from the spec's `spec.md`,
    //! plus a `rejects_invalid_examples` test for any fixtures
    //! in `payload.invalid-examples.json` (validate feature).
    /// Each fixture in `payload.invalid-examples.json` MUST be
    /// rejected by at least one of: serde deserialization, or
    /// JSON-Schema validation under the `validate` feature. The
    /// fixture file documents the producer-side bug class that
    /// each payload exemplifies; this generated test pins it.
    #[cfg(feature = "validate")]
    #[test]
    fn rejects_invalid_examples() {
        use crate::validate::ValidatedPayload;
        let fixtures: &[(&str, &str)] = &[
            (
                "Empty payload omits required member(s): conversationId, direction, sentAt.",
                "{}",
            ),
            (
                "Unknown top-level member is rejected (additionalProperties: false).",
                "{\n  \"__notARealMember__\": true,\n  \"conversationId\": \"c-1\",\n  \"direction\": \"outbound\",\n  \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
            ),
            (
                "`direction` must be one of the enum values (inbound | outbound).",
                "{\n  \"conversationId\": \"c-1\",\n  \"direction\": \"sideways\",\n  \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
            ),
            (
                "`conversationId` has the wrong type (expected string).",
                "{\n  \"conversationId\": 12345,\n  \"direction\": \"inbound\",\n  \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
            ),
            (
                "`prev` is missing its required `digest` (an unverifiable chain link is rejected).",
                "{\n  \"conversationId\": \"c-1\",\n  \"direction\": \"outbound\",\n  \"prev\": {\n    \"id\": \"urn:uuid:prev\"\n  },\n  \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
            ),
            (
                "An attachment reference omits the required `mediaType`.",
                "{\n  \"attachments\": [\n    {\n      \"id\": \"att-1\"\n    }\n  ],\n  \"conversationId\": \"c-1\",\n  \"direction\": \"inbound\",\n  \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
            ),
        ];
        for (i, (note, raw)) in fixtures.iter().enumerate() {
            let value: serde_json::Value = match serde_json::from_str(raw) {
                Ok(v) => v,
                Err(_) => continue,
            };
            let serde_ok = serde_json::from_value::<super::Payload>(value.clone()).is_ok();
            let schema_ok = super::Payload::validate_value(&value).is_ok();
            assert!(
                !(serde_ok && schema_ok),
                "invalid-example #{} ({:?}) was accepted by both serde and JSON Schema; \
                         the fixture's stated failure class is no longer caught:\n{}",
                i + 1,
                note,
                raw
            );
        }
    }
}