-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36a7823
commit c332eca
Showing
9 changed files
with
183 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use clap::Subcommand; | ||
use keri_controller::{IdentifierPrefix, LocationScheme}; | ||
|
||
use crate::temporary_identifier::generate_temporary_identifier; | ||
|
||
#[derive(Subcommand)] | ||
pub enum DebugCommand { | ||
Ksn { | ||
/// Source OOBI in json | ||
#[arg(short, long)] | ||
source: String, | ||
#[arg(short, long)] | ||
id: IdentifierPrefix, | ||
}, | ||
Tel { | ||
/// Source OOBI in json | ||
#[arg(short, long)] | ||
source: String, | ||
#[arg(short, long)] | ||
registry_id: IdentifierPrefix, | ||
#[arg(short, long)] | ||
vc_id: Option<IdentifierPrefix>, | ||
}, | ||
Kel { | ||
/// Source OOBI in json | ||
#[arg(short, long)] | ||
source: String, | ||
#[arg(short, long)] | ||
identifier: IdentifierPrefix, | ||
#[arg(long)] | ||
sn: u64, | ||
#[arg(short, long)] | ||
limit: Option<u64>, | ||
} | ||
} | ||
|
||
pub async fn process_debug_command(cmd: DebugCommand) { | ||
match cmd { | ||
DebugCommand::Ksn { source, id } => { | ||
let tmp_id = generate_temporary_identifier().unwrap(); | ||
let source: LocationScheme = serde_json::from_str(&source).unwrap(); | ||
|
||
let ksn = tmp_id.pull_ksn(id, source).await.unwrap(); | ||
|
||
println!("{}", &ksn); | ||
|
||
}, | ||
DebugCommand::Tel { source, vc_id, registry_id: id } => { | ||
let tmp_id = generate_temporary_identifier().unwrap(); | ||
let source: LocationScheme = serde_json::from_str(&source).unwrap(); | ||
|
||
let tel = tmp_id.pull_tel(&id, vc_id, source).await; | ||
|
||
println!("{}", &tel); | ||
}, | ||
DebugCommand::Kel { source, identifier, sn, limit } => { | ||
let tmp_id = generate_temporary_identifier().unwrap(); | ||
let source: LocationScheme = serde_json::from_str(&source).unwrap(); | ||
|
||
let limit = limit.unwrap_or(1); | ||
let kel = tmp_id.pull_kel(identifier.clone(), sn, limit, source).await.unwrap(); | ||
match kel { | ||
Some(kel) => { | ||
let kel_str = kel.into_iter().map(|event| String::from_utf8(event.to_cesr().unwrap()).unwrap()).collect::<Vec<_>>().join("\n"); | ||
println!("{}", kel_str); | ||
|
||
}, | ||
None => println!("Identifier {} not found", identifier.to_string()), | ||
} | ||
|
||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod key; | |
pub mod log; | ||
pub mod mesagkesto; | ||
pub mod said; | ||
pub mod debug; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::sync::Arc; | ||
|
||
use keri_controller::{communication::{Communication, SendingError}, error::ControllerError, identifier::nontransferable::NontransferableIdentifier, known_events::KnownEvents, BasicPrefix, IdentifierPrefix, LocationScheme}; | ||
use keri_core::{actor::{error::ActorError, prelude::Message, simple_controller::PossibleResponse, QueryError, SignedQueryError}, processor::escrow::EscrowConfig, signer::Signer, transport::default::DefaultTransport}; | ||
use teliox::transport::TelTransport; | ||
use tempfile::Builder; | ||
|
||
use crate::export::ExportError; | ||
|
||
pub struct TemporaryIdentifier { | ||
signer: Arc<Signer>, | ||
id: NontransferableIdentifier | ||
} | ||
|
||
pub fn generate_temporary_identifier() -> Result<TemporaryIdentifier, ExportError> { | ||
// create temporary identifier to pull KEL from witnesses | ||
let signer = Arc::new(Signer::new()); | ||
let bp = BasicPrefix::Ed25519NT(signer.public_key()); | ||
let transport = Box::new(DefaultTransport::new()); | ||
let tel_transport = Box::new(TelTransport); | ||
let tmp_dir = Builder::new().prefix("tmp-dir").tempdir().map_err(|_e| ExportError::TemporaryId("Temporary file creation error".to_string()))?; | ||
|
||
let tmp_events = | ||
Arc::new(KnownEvents::new(tmp_dir.path().to_path_buf(), EscrowConfig::default()).map_err(|_e| ExportError::TemporaryId("Temporary identifier creation error".to_string()))?); | ||
let comm = Arc::new(Communication { | ||
events: tmp_events.clone(), | ||
transport, | ||
tel_transport, | ||
}); | ||
let tmp_id = NontransferableIdentifier::new(bp, comm.clone()); | ||
Ok(TemporaryIdentifier { signer, id: tmp_id }) | ||
} | ||
|
||
impl TemporaryIdentifier { | ||
pub async fn pull_kel(&self, id: IdentifierPrefix, sn: u64, limit: u64, witness_location: LocationScheme) -> Result<Option<Vec<Message>>, ControllerError> { | ||
let witness_id = match &witness_location.eid { | ||
IdentifierPrefix::Basic(basic_prefix) => basic_prefix.clone(), | ||
_ => unreachable!("Witness identifier must be basic prefix"), | ||
}; | ||
|
||
let qry = self.id.query_log(id, sn, limit, witness_id); | ||
let signature = self.id.sign(self.signer.sign(qry.encode()?).unwrap()); | ||
let resp = self.id | ||
.finalize_query(witness_location, qry, signature) | ||
.await; | ||
match resp { | ||
Ok(PossibleResponse::Kel(vec)) => Ok(Some(vec)), | ||
Ok(_) => unreachable!("Unexpected response from witness"), | ||
Err(ControllerError::SendingError(SendingError::ActorInternalError(ActorError::QueryError(SignedQueryError::QueryError(QueryError::UnknownId { id: _ }))))) => Ok(None), | ||
Err(e) => Err(e) | ||
} | ||
} | ||
|
||
|
||
pub async fn pull_ksn(&self, id: IdentifierPrefix, witness_location: LocationScheme) -> Result<String, ControllerError> { | ||
let witness_id = match &witness_location.eid { | ||
IdentifierPrefix::Basic(basic_prefix) => basic_prefix.clone(), | ||
_ => unreachable!("Witness identifier must be basic prefix"), | ||
}; | ||
|
||
let qry = self.id.query_ksn(&id, witness_id); | ||
let signature = self.id.sign(self.signer.sign(qry.encode()?).unwrap()); | ||
let resp = self.id | ||
.finalize_query(witness_location, qry, signature) | ||
.await?; | ||
match resp { | ||
PossibleResponse::Ksn(ksn) => { | ||
let ksn = serde_json::to_string_pretty(&ksn.reply.data).unwrap(); | ||
Ok(ksn) | ||
}, | ||
_ => unreachable!("Unexpected response from witness"), | ||
} | ||
} | ||
|
||
|
||
pub async fn pull_tel(&self, registry_id: &IdentifierPrefix, vc_id: Option<IdentifierPrefix>, witness: LocationScheme) -> String { | ||
let tel_qry = self.id.query_tel(registry_id.clone(), vc_id).unwrap(); | ||
let signature = self.signer.sign(tel_qry.encode().unwrap()).unwrap(); | ||
let sig = self.id.sign(signature); | ||
self.id.finalize_query_tel(witness, tel_qry, sig).await.unwrap() | ||
} | ||
} |