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
// SPDX-License-Identifier: AGPL-3.0-or-later
//! # p2panda-rs
//!
//! This library provides all tools required to write a client for the [p2panda] network. It is
//! shipped both as a Rust crate `p2panda-rs` with WebAssembly bindings and a NPM package
//! `p2panda-js` with TypeScript definitions running in NodeJS or any modern web browser.
//!
//! [p2panda]: https://p2panda.org
//!
//! ## Example
//!
//! Creates and signs data which can be sent to a p2panda node.
//!
//! ```
//! # extern crate p2panda_rs;
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # use std::convert::TryFrom;
//! # use p2panda_rs::entry::EntryBuilder;
//! # use p2panda_rs::entry::encode::encode_entry;
//! # use p2panda_rs::hash::Hash;
//! # use p2panda_rs::identity::KeyPair;
//! # use p2panda_rs::operation::{OperationBuilder, OperationId};
//! # use p2panda_rs::operation::encode::encode_operation;
//! # use p2panda_rs::schema::{SchemaId, SchemaName};
//! #
//! # let schema_name = SchemaName::new("profile")?;
//! # let view_id = OperationId::from(Hash::new_from_bytes(&[1, 2, 3]));
//! # let profile_schema_id = SchemaId::new_application(&schema_name, &view_id.into());
//! // Generate new Ed25519 key pair
//! let key_pair = KeyPair::new();
//!
//! // Add field data to "create" operation
//! let operation = OperationBuilder::new(&profile_schema_id)
//! .fields(&[("username", "panda".into())])
//! .build()?;
//!
//! // Encode operation into bytes
//! let encoded_operation = encode_operation(&operation)?;
//!
//! // Create Bamboo entry (append-only log data type) with operation as payload
//! let entry = EntryBuilder::new()
//! .sign(&encoded_operation, &key_pair)?;
//!
//! // Encode entry into bytes
//! let encoded_entry = encode_entry(&entry)?;
//!
//! println!("{} {}", encoded_entry, encoded_operation);
//! # Ok(())
//! # }
//! ```
// This must be imported here at the root of the crate in order for the `rstest` fixture macros to
// work as expected.
use rstest_reuse;
/// Trait used by p2panda structs to validate data formats.
///
/// Use this trait to check against (canonic) formats of data (like document ids or yasmf hashes)
/// coming in via deserialization, constructors or (string) conversion.
/// Trait used by p2panda structs for human-facing functionality, like better readability.
///
/// Please note: Most structs already provide string representation methods which can be used for
/// debugging with additional type information (`Debug`) or lossless string representations of the
/// data (`Display`). `Display` implementations return a string which can safely be parsed back
/// into the struct again. `Human` takes a third approach which is potentially destructive and aims
/// at easier to read strings.
/// Trait used by p2panda structs which contain at least one id.
///
/// A single struct may have several id's, common use cases will be `WithId<OperationId>`,
/// `WithId<DocumentId>` and `WithId<SchemaId>`.
/// Init pretty_env_logger before the test suite runs to handle logging outputs.
///
/// We output log information using the `log` crate. In itself this doesn't print
/// out any logging information, library users can capture and handle the emitted logs
/// using a log handler. Here we use `pretty_env_logger` to handle logs emitted
/// while running our tests.
///
/// This will also capture and output any logs emitted from our dependencies. This behaviour
/// can be customised at runtime. With eg. `RUST_LOG=p2panda=info cargo t` or
/// `RUST_LOG=openmls=debug cargo t`.
///
/// The `ctor` crate is used to define a global constructor function. This method
/// will be run before any of the test suites.