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
// 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::{sign_and_encode, Entry, EntrySigned, LogId, SeqNum};
//! # use p2panda_rs::hash::Hash;
//! # use p2panda_rs::identity::KeyPair;
//! # use p2panda_rs::operation::{Operation, OperationFields, OperationValue, OperationId, Relation};
//! # use p2panda_rs::schema::SchemaId;
//! # use p2panda_rs::document::{DocumentId, DocumentViewId};
//! # let profile_schema_view_id = OperationId::from(
//! # Hash::new_from_bytes(vec![1, 2, 3])?
//! # );
//! # let profile_schema = SchemaId::new_application("profile", &profile_schema_view_id.into());
//! // Generate new Ed25519 key pair
//! let key_pair = KeyPair::new();
//!
//! // Create operation fields which contain the data we want to send
//! let mut fields = OperationFields::new();
//! fields.add("username", OperationValue::Text("panda".to_owned()))?;
//!
//! // Add field data to "create" operation
//! let operation = Operation::new_create(profile_schema, fields)?;
//!
//! // This is the entry at sequence number 1 (the first entry in the log)
//! let seq_num = SeqNum::new(1)?;
//!
//! // Wrap operation into Bamboo entry (append-only log data type)
//! let entry = Entry::new(&LogId::default(), Some(&operation), None, None, &seq_num)?;
//!
//! // Sign entry with private key
//! let entry_signed = sign_and_encode(&entry, &key_pair)?;
//! # 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;
extern crate proptest;
/// Trait used by p2panda structs to validate arguments.
/// 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.