Skip to content

Commit

Permalink
I think mainly done moving modules around
Browse files Browse the repository at this point in the history
  • Loading branch information
expede committed Jan 31, 2024
1 parent 9c6fb07 commit fdaae6c
Show file tree
Hide file tree
Showing 37 changed files with 200 additions and 106 deletions.
1 change: 1 addition & 0 deletions src/ability.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// FIXME feature flag each?
pub mod crud;
pub mod msg;
pub mod ucan;
pub mod wasm;

pub mod arguments;
Expand Down
16 changes: 16 additions & 0 deletions src/ability/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ impl Arguments {
}
}

impl Arguments {
pub fn insert(&mut self, key: String, value: Ipld) -> Option<Ipld> {
self.0.insert(key, value)
}

pub fn get(&self, key: &str) -> Option<&Ipld> {
self.0.get(key)
}
}

impl Default for Arguments {
fn default() -> Self {
Arguments(BTreeMap::new())
}
}

impl TryFrom<Ipld> for Arguments {
type Error = SerdeError;

Expand Down
4 changes: 1 addition & 3 deletions src/ability/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! This module is for dynamic abilities, especially for FFI and Wasm support

use super::{arguments::Arguments, command::ToCommand};
use crate::{
delegation::delegatable::Delegatable, invocation::resolvable::Resolvable, promise::Promise,
};
use crate::{delegate::Delegatable, invoke::Resolvable, promise::Promise};
use serde_derive::{Deserialize, Serialize};
use std::fmt::Debug;

Expand Down
4 changes: 2 additions & 2 deletions src/ability/msg/send.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
ability::{arguments::Arguments, command::Command},
delegation::delegatable::Delegatable,
invocation::resolvable::Resolvable,
delegate::Delegatable,
invoke::Resolvable,
promise::Promise,
proof::{checkable::Checkable, parentful::Parentful, parents::CheckParents, same::CheckSame},
};
Expand Down
82 changes: 82 additions & 0 deletions src/ability/ucan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use super::arguments::Arguments;
use crate::{ability::command::Command, delegate::Delegatable, promise::Promise};
use libipld_core::ipld::Ipld;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

// NOTE This one is primarily for enabling delegated recipets

// FIXME
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Generic<Args> {
pub cmd: String,
pub args: Args, // FIXME Does this have specific fields?
}

pub type Resolved = Generic<Arguments>;
pub type Builder = Generic<Option<Arguments>>;
pub type Promised = Generic<Promise<Arguments>>;

impl<Args> Command for Generic<Args> {
const COMMAND: &'static str = "ucan/proxy";
}

impl Delegatable for Resolved {
type Builder = Builder;
}

impl From<Resolved> for Builder {
fn from(resolved: Resolved) -> Builder {
Builder {
cmd: resolved.cmd,
args: Some(resolved.args),
}
}
}

impl TryFrom<Builder> for Resolved {
type Error = (); // FIXME

fn try_from(b: Builder) -> Result<Self, Self::Error> {
Ok(Resolved {
cmd: b.cmd,
args: b.args.ok_or(())?,
})
}
}

impl From<Builder> for Arguments {
fn from(b: Builder) -> Arguments {
let mut args = b.args.unwrap_or_default();
args.insert("cmd".into(), Ipld::String(b.cmd));
args
}
}

// // FIXME hmmm
// #[derive(Debug, Clone, PartialEq)]
// pub struct ProxyExecuteBuilder {
// pub command: Option<String>,
// pub args: BTreeMap<String, Ipld>,
// }
//
//
// impl From<ProxyExecute> for ProxyExecuteBuilder {
// fn from(proxy: ProxyExecute) -> Self {
// ProxyExecuteBuilder {
// command: Some(ProxyExecute::COMMAND.into()),
// args: proxy.args.clone(),
// }
// }
// }
//
// impl TryFrom<ProxyExecuteBuilder> for ProxyExecute {
// type Error = (); // FIXME
//
// fn try_from(ProxyExecuteBuilder { command, args }: ProxyExecuteBuilder) -> Result<Self, ()> {
// match command {
// None => Err(()),
// Some(command) => Ok(Self { command, args }),
// }
// }
// }
1 change: 0 additions & 1 deletion src/condition.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/condition/common.rs

This file was deleted.

13 changes: 7 additions & 6 deletions src/delegation.rs → src/delegate.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// FIXME rename delegate?

pub mod condition;
pub mod delegatable;
pub mod delegate;
pub mod payload;
mod condition;
mod delegatable;
mod payload;

use crate::signature;
pub use delegate::Delegate;
pub use condition::traits::Condition;
pub use delegatable::Delegatable;
pub use payload::Payload;

use crate::signature;

/// A [`Delegation`] is a signed delegation [`Payload`]
///
/// A [`Payload`] on its own is not a valid [`Delegation`], as it must be signed by the issuer.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions src/delegation/payload.rs → src/delegate/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::{
ability::{arguments::Arguments, command::Command, dynamic},
capsule::Capsule,
did::Did,
invocation::{payload as invocation, resolvable::Resolvable},
invoke,
invoke::Resolvable,
nonce::Nonce,
proof::{
checkable::Checkable,
Expand Down Expand Up @@ -89,14 +90,14 @@ impl<T: Delegatable, C: Condition> From<Payload<T, C>> for Ipld {

impl<'a, T: Delegatable + Resolvable + Checkable + Clone, C: Condition> Payload<T, C> {
pub fn check<U: Delegatable + Clone>(
invoked: &'a invocation::Payload<T>, // FIXME promisory version
invoked: &'a invoke::Payload<T>, // FIXME promisory version
proofs: Vec<Payload<U, C>>,
now: SystemTime,
) -> Result<(), ()>
where
invocation::Payload<T>: Clone,
invoke::Payload<T>: Clone,
U::Builder: Clone + Into<T::Hierarchy>,
T::Hierarchy: From<invocation::Payload<T>>,
T::Hierarchy: From<invoke::Payload<T>>,
{
let start: Acc<'a, T> = Acc {
issuer: &invoked.issuer,
Expand Down
File renamed without changes.
19 changes: 0 additions & 19 deletions src/delegation/delegate.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/invocation/serializer.rs

This file was deleted.

7 changes: 5 additions & 2 deletions src/invocation.rs → src/invoke.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
pub mod payload;
pub mod resolvable;
mod payload;
mod resolvable;
mod serializer;

pub use payload::Payload;
pub use resolvable::Resolvable;

use crate::signature;

pub type Invocation<B> = signature::Envelope<payload::Payload<B>>;
File renamed without changes.
File renamed without changes.
Empty file added src/invoke/serializer.rs
Empty file.
10 changes: 5 additions & 5 deletions src/ipld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ use libipld_core::ipld::Ipld;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::JsValue;

pub struct WrappedIpld(pub Ipld);
pub struct Newtype(pub Ipld);

impl From<Ipld> for WrappedIpld {
impl From<Ipld> for Newtype {
fn from(ipld: Ipld) -> Self {
Self(ipld)
}
}

impl From<WrappedIpld> for Ipld {
fn from(wrapped: WrappedIpld) -> Self {
impl From<Newtype> for Ipld {
fn from(wrapped: Newtype) -> Self {
wrapped.0
}
}

// TODO testme
#[cfg(target_arch = "wasm32")]
impl From<WrappedIpld> for JsValue {
impl From<Newtype> for JsValue {
fn from(wrapped: WrappedIpld) -> Self {
match wrapped.0 {
Ipld::Null => JsValue::Null,
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ use std::fmt::Debug;

pub mod ability;
pub mod capsule;
pub mod delegation;
pub mod invocation;
pub mod delegate;
pub mod invoke;
pub mod ipld;
pub mod nonce;
pub mod number;
pub mod promise;
pub mod proof;
pub mod receipt;
pub mod respond;
pub mod signature;
pub mod task;

Expand Down
2 changes: 2 additions & 0 deletions src/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use libipld_core::{ipld::Ipld, serde as ipld_serde};
use serde_derive::{Deserialize, Serialize};
use std::fmt::Debug;

// FIXME move under invoke?

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Promise<T> {
Expand Down
51 changes: 0 additions & 51 deletions src/receipt.rs

This file was deleted.

9 changes: 9 additions & 0 deletions src/respond.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mod payload;
mod responds;

pub use payload::Payload;
pub use responds::Responds;

use crate::signature;

pub type Receipt<T> = signature::Envelope<Payload<T>>;
12 changes: 6 additions & 6 deletions src/receipt/payload.rs → src/respond/payload.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::runnable::Runnable;
use super::responds::Responds;
use crate::{capsule::Capsule, did::Did, nonce::Nonce, time::Timestamp};
use libipld_core::{cid::Cid, ipld::Ipld, serde as ipld_serde};
use serde::{de::DeserializeOwned, Deserialize, Serialize, Serializer};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{collections::BTreeMap, fmt::Debug};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Payload<T: Runnable>
pub struct Payload<T: Responds>
where
T::Success: Serialize + DeserializeOwned,
{
Expand All @@ -22,14 +22,14 @@ where
pub issued_at: Option<Timestamp>,
}

impl<T: Runnable> Capsule for Payload<T>
impl<T: Responds> Capsule for Payload<T>
where
for<'de> T::Success: Serialize + Deserialize<'de>,
{
const TAG: &'static str = "ucan/r/1.0.0-rc.1"; // FIXME extract out version
}

impl<T: Runnable> TryFrom<Ipld> for Payload<T>
impl<T: Responds> TryFrom<Ipld> for Payload<T>
where
for<'de> T::Success: Serialize + Deserialize<'de>,
{
Expand All @@ -40,7 +40,7 @@ where
}
}

impl<T: Runnable> From<Payload<T>> for Ipld
impl<T: Responds> From<Payload<T>> for Ipld
where
for<'de> T::Success: Serialize + Deserialize<'de>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/receipt/runnable.rs → src/respond/responds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{did::Did, nonce::Nonce, task, task::Task};

pub trait Runnable {
pub trait Responds {
type Success;

fn to_task(&self, subject: Did, nonce: Nonce) -> Task;
Expand Down
Loading

0 comments on commit fdaae6c

Please sign in to comment.