diff --git a/documents/blockchain/v10/documents/mod.rs b/documents/blockchain/v10/documents/mod.rs index 4c0d6f38c23b3763c4f9e716afd37f71589258df..d2eb531b296e7c3314300e3a35427ae71bedd497 100644 --- a/documents/blockchain/v10/documents/mod.rs +++ b/documents/blockchain/v10/documents/mod.rs @@ -15,6 +15,10 @@ //! Provide wrappers around Duniter blockchain documents for protocol version 10. +extern crate crypto; + +use self::crypto::digest::Digest; + use duniter_crypto::keys::{Signature, ed25519}; use regex::Regex; use blockchain::{Document, DocumentBuilder, DocumentParser}; @@ -72,6 +76,12 @@ pub trait TextDocument: Document<PublicKey = ed25519::PublicKey, CurrencyType = /// Return document as text. fn as_text(&self) -> &str; + /// Return sha256 hash of text document + fn hash<H: Digest>(&self, digest: &mut H) -> String { + digest.input_str(self.as_text()); + digest.result_str() + } + /// Return document as text with leading signatures. fn as_text_with_signatures(&self) -> String { let mut text = self.as_text().to_string();