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

Commit

Permalink
change salt => parameters for create, update verify_oid_v0
Browse files Browse the repository at this point in the history
  • Loading branch information
chunningham committed May 17, 2021
1 parent 7a83b13 commit d2b33bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
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
16 changes: 12 additions & 4 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
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

0 comments on commit d2b33bc

Please sign in to comment.