Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

update OID input #27

Merged
merged 2 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum Action {
},
Create {
orbit_id: Cid,
salt: String,
parameters: String,
content: Vec<Cid>,
},
}
Expand Down
23 changes: 17 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ async fn batch_put_create(
auth: AuthWrapper<TezosAuthorizationString>,
) -> Result<String, Debug<Error>> {
match auth.0.action() {
Action::Create { orbit_id, salt, .. } => {
verify_oid_v0(orbit_id, &auth.0.pkh, salt)?;
Action::Create {
orbit_id,
parameters,
..
} => {
verify_oid_v0(orbit_id, &auth.0.pkh, parameters)?;

let vm = DIDURL {
did: format!("did:pkh:tz:{}", &auth.0.pkh),
Expand Down Expand Up @@ -255,8 +259,12 @@ async fn put_create(
auth: AuthWrapper<TezosAuthorizationString>,
) -> Result<String, Debug<Error>> {
match auth.0.action() {
Action::Create { orbit_id, salt, .. } => {
verify_oid_v0(orbit_id, &auth.0.pkh, salt)?;
Action::Create {
orbit_id,
parameters,
..
} => {
verify_oid_v0(orbit_id, &auth.0.pkh, parameters)?;

let vm = DIDURL {
did: format!("did:pkh:tz:{}", &auth.0.pkh),
Expand Down Expand Up @@ -324,8 +332,11 @@ async fn main() {
let kepler_config = config.extract::<config::Config>().unwrap();

// ensure KEPLER_DATABASE_PATH exists
if kepler_config.database.path.is_dir() {
panic!("KEPLER_DATABASE_PATH does not exist or is not a directory");
if !kepler_config.database.path.is_dir() {
panic!(
"KEPLER_DATABASE_PATH does not exist or is not a directory: {}",
kepler_config.database.path.to_str().unwrap()
);
}

rocket::custom(config.clone())
Expand Down
11 changes: 7 additions & 4 deletions src/orbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use libipld::{
store::DefaultParams,
};
use libp2p_core::PeerId;
use rocket::{futures::stream::StreamExt, tokio::fs};
use rocket::{futures::stream::StreamExt, http::uri::Absolute, tokio::fs};
use serde::{Deserialize, Serialize};
use ssi::did::DIDURL;
use std::{convert::TryFrom, path::Path};
Expand Down Expand Up @@ -147,9 +147,12 @@ where
})
}

pub fn verify_oid_v0(oid: &Cid, pkh: &str, salt: &str) -> Result<()> {
if &Code::try_from(oid.hash().code())?.digest(format!("{}:{}", salt, pkh).as_bytes())
== oid.hash()
pub fn verify_oid_v0(oid: &Cid, pkh: &str, params: &str) -> Result<()> {
let uri = format!("tz:{}{}", pkh, params);
// try to parse as a URL with query params
Absolute::parse(&uri).map_err(|_| anyhow!("Orbit Parameters Invalid"))?;
if &Code::try_from(oid.hash().code())?.digest(uri.as_bytes()) == oid.hash()
&& oid.codec() == 0x55
{
Ok(())
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ fn parse_create(s: &str) -> IResult<&str, Action> {
tuple((
map_parser(take_until(" "), parse_cid),
tag(" CREATE"),
space_delimit, // salt (orbit secret + nonce)
space_delimit, // parameters
many1(map_parser(space_delimit, parse_cid)),
))(s)
.map(|(rest, (orbit_id, _, salt, content))| {
.map(|(rest, (orbit_id, _, params, content))| {
(
rest,
Action::Create {
orbit_id,
content,
salt: salt.into(),
parameters: params.into(),
},
)
})
Expand All @@ -122,11 +122,11 @@ fn serialize_action(action: &Action) -> Result<String> {
Action::Create {
orbit_id,
content,
salt,
parameters,
} => Ok([
&orbit_id.to_string_of_base(Base::Base58Btc)?,
"CREATE",
&salt,
&parameters,
&content
.iter()
.map(|c| c.to_string_of_base(Base::Base58Btc))
Expand Down