Select Git revision
-
Cédric Moreau authoredCédric Moreau authored
identity.rs 8.28 KiB
// Copyright (C) 2018 The Duniter Project Developers.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Wrappers around Identity documents.
use duniter_crypto::keys::{PublicKey, ed25519};
use regex::Regex;
use Blockstamp;
use blockchain::{BlockchainProtocol, Document, DocumentBuilder, IntoSpecializedDocument};
use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder,
V10Document, V10DocumentParsingError};
lazy_static! {
static ref IDENTITY_REGEX: Regex = Regex::new(
"^Issuer: (?P<issuer>[1-9A-Za-z][^OIl]{43,44})\nUniqueID: (?P<uid>[[:alnum:]_-]+)\nTimestamp: (?P<blockstamp>[0-9]+-[0-9A-F]{64})\n$"
).unwrap();
}
/// Wrap an Identity document.
///
/// Must be created by parsing a text document or using a builder.
#[derive(Debug, Clone)]
pub struct IdentityDocument {
/// Document as text.
///
/// Is used to check signatures, and other values
/// must be extracted from it.
text: String,
/// Currency.
currency: String,
/// Unique ID
unique_id: String,
/// Blockstamp
blockstamp: Blockstamp,
/// Document issuer (there should be only one).
issuers: Vec<ed25519::PublicKey>,
/// Document signature (there should be only one).
signatures: Vec<ed25519::Signature>,
}
impl IdentityDocument {
/// Unique ID
pub fn unique_id(&self) -> &str {
&self.unique_id
}
}
impl Document for IdentityDocument {
type PublicKey = ed25519::PublicKey;
type CurrencyType = str;
fn version(&self) -> u16 {
10
}
fn currency(&self) -> &str {