Skip to content

Commit

Permalink
refactor: Remove unused constraints (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Mar 27, 2024
1 parent 5dbd296 commit 7f680d3
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 147 deletions.
8 changes: 4 additions & 4 deletions src/ability/pipe.rs
@@ -1,22 +1,22 @@
use crate::{crypto::varsig, delegation, did::Did, ipld};
use libipld_core::{codec::Codec, ipld::Ipld};

pub struct Pipe<DID: Did, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>> {
pub struct Pipe<DID: Did, V: varsig::Header<C>, C: Codec> {
pub source: Cap<DID, V, C>,
pub sink: Cap<DID, V, C>,
}

pub enum Cap<DID: Did, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>> {
pub enum Cap<DID: Did, V: varsig::Header<C>, C: Codec> {
Proof(delegation::Proof<DID, V, C>),
Literal(Ipld),
}

pub struct PromisedPipe<DID: Did, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>> {
pub struct PromisedPipe<DID: Did, V: varsig::Header<C>, C: Codec> {
pub source: PromisedCap<DID, V, C>,
pub sink: PromisedCap<DID, V, C>,
}

pub enum PromisedCap<DID: Did, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>> {
pub enum PromisedCap<DID: Did, V: varsig::Header<C>, C: Codec> {
Proof(delegation::Proof<DID, V, C>),
Promised(ipld::Promised),
}
4 changes: 2 additions & 2 deletions src/ability/ucan/batch.rs
Expand Up @@ -3,11 +3,11 @@
// use std::collections::BTreeMap;
//
// #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
// pub struct Batch<A, DID: Did, V: varsig::Header<Enc>, Enc: Codec + TryFrom<u64> + Into<u64>> {
// pub struct Batch<A, DID: Did, V: varsig::Header<Enc>, Enc: Codec> {
// pub batch: Vec<Step<A, DID, V, Enc>>, // FIXME not quite right; would be nice to include meta etc
// }
//
// pub struct Step<A, DID: Did, V: varsig::Header<Enc>, Enc: Codec + TryFrom<u64> + Into<u64>> {
// pub struct Step<A, DID: Did, V: varsig::Header<Enc>, Enc: Codec> {
// pub subject: DID,
// pub audience: Option<DID>,
// pub ability: A, // FIXME promise version instead? Promised version shoudl be able to promise any field
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/signature/envelope.rs
Expand Up @@ -16,7 +16,7 @@ pub trait Envelope: Sized {
type DID: Did;
type Payload: Clone + Capsule + TryFrom<Named<Ipld>> + Into<Named<Ipld>>;
type VarsigHeader: varsig::Header<Self::Encoder> + Clone;
type Encoder: Codec + TryFrom<u64> + Into<u64>;
type Encoder: Codec;

fn varsig_header(&self) -> &Self::VarsigHeader;
fn signature(&self) -> &<Self::DID as Did>::Signature;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/varsig/header/eddsa.rs
Expand Up @@ -33,7 +33,7 @@ impl<C: Into<u64> + Clone> From<EdDsaHeader<C>> for Vec<u8> {
}
}

impl<C: Codec + Into<u64> + TryFrom<u64>> Header<C> for EdDsaHeader<C> {
impl<C: Codec> Header<C> for EdDsaHeader<C> {
type Signature = ed25519_dalek::Signature;
type Verifier = ed25519_dalek::VerifyingKey;

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/varsig/header/es256.rs
Expand Up @@ -38,7 +38,7 @@ impl<C: Into<u64>> From<Es256Header<C>> for Vec<u8> {
}
}

impl<C: Codec + Into<u64> + TryFrom<u64>> Header<C> for Es256Header<C> {
impl<C: Codec> Header<C> for Es256Header<C> {
type Signature = p256::ecdsa::Signature;
type Verifier = p256::ecdsa::VerifyingKey;

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/varsig/header/es256k.rs
Expand Up @@ -38,7 +38,7 @@ impl<C: Into<u64>> From<Es256kHeader<C>> for Vec<u8> {
}
}

impl<C: Codec + Into<u64> + TryFrom<u64>> Header<C> for Es256kHeader<C> {
impl<C: Codec> Header<C> for Es256kHeader<C> {
type Signature = k256::ecdsa::Signature;
type Verifier = k256::ecdsa::VerifyingKey;

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/varsig/header/es512.rs
Expand Up @@ -38,7 +38,7 @@ impl<C: Into<u64>> From<Es512Header<C>> for Vec<u8> {
}
}

impl<C: Codec + Into<u64> + TryFrom<u64>> Header<C> for Es512Header<C> {
impl<C: Codec> Header<C> for Es512Header<C> {
type Signature = p521::ecdsa::Signature;
type Verifier = p521::ecdsa::VerifyingKey;

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/varsig/header/rs256.rs
Expand Up @@ -51,7 +51,7 @@ impl<C: Into<u64>> From<Rs256Header<C>> for Vec<u8> {
}
}

impl<C: Codec + Into<u64> + TryFrom<u64>> Header<C> for Rs256Header<C> {
impl<C: Codec> Header<C> for Rs256Header<C> {
type Signature = Signature;
type Verifier = VerifyingKey;

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/varsig/header/rs512.rs
Expand Up @@ -39,7 +39,7 @@ impl<C: Into<u64>> From<Rs512Header<C>> for Vec<u8> {
}
}

impl<C: Codec + Into<u64> + TryFrom<u64>> Header<C> for Rs512Header<C> {
impl<C: Codec> Header<C> for Rs512Header<C> {
type Signature = Signature;
type Verifier = VerifyingKey;

Expand Down
4 changes: 1 addition & 3 deletions src/crypto/varsig/header/traits.rs
Expand Up @@ -2,9 +2,7 @@ use libipld_core::codec::{Codec, Encode};
use signature::Verifier;
use thiserror::Error;

pub trait Header<Enc: Codec + TryFrom<u64> + Into<u64>>:
for<'a> TryFrom<&'a [u8]> + Into<Vec<u8>>
{
pub trait Header<Enc: Codec>: for<'a> TryFrom<&'a [u8]> + Into<Vec<u8>> {
type Signature: signature::SignatureEncoding;
type Verifier: signature::Verifier<Self::Signature>;

Expand Down
20 changes: 8 additions & 12 deletions src/delegation.rs
Expand Up @@ -42,7 +42,7 @@ use web_time::SystemTime;
pub struct Delegation<
DID: Did = did::preset::Verifier,
V: varsig::Header<C> = varsig::header::Preset,
C: Codec + TryFrom<u64> + Into<u64> = varsig::encoding::Preset,
C: Codec = varsig::encoding::Preset,
> {
pub varsig_header: V,
pub payload: Payload<DID>,
Expand All @@ -54,18 +54,16 @@ pub struct Delegation<
pub struct Proof<
DID: Did = did::preset::Verifier,
V: varsig::Header<C> = varsig::header::Preset,
C: Codec + TryFrom<u64> + Into<u64> = varsig::encoding::Preset,
C: Codec = varsig::encoding::Preset,
> {
pub prf: Vec<Link<Delegation<DID, V, C>>>,
}

impl<DID: Did, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>> Capsule
for Proof<DID, V, C>
{
impl<DID: Did, V: varsig::Header<C>, C: Codec> Capsule for Proof<DID, V, C> {
const TAG: &'static str = "ucan/prf";
}

impl<DID: Did, V: varsig::Header<C>, C: Codec + Into<u64> + TryFrom<u64>> Delegation<DID, V, C> {
impl<DID: Did, V: varsig::Header<C>, C: Codec> Delegation<DID, V, C> {
pub fn new(
varsig_header: V,
signature: DID::Signature,
Expand Down Expand Up @@ -124,8 +122,7 @@ impl<DID: Did, V: varsig::Header<C>, C: Codec + Into<u64> + TryFrom<u64>> Delega
}
}

impl<DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec + TryFrom<u64> + Into<u64>> Envelope
for Delegation<DID, V, C>
impl<DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec> Envelope for Delegation<DID, V, C>
where
Payload<DID>: TryFrom<Named<Ipld>>,
Named<Ipld>: From<Payload<DID>>,
Expand Down Expand Up @@ -165,8 +162,7 @@ where
}
}

impl<DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec + TryFrom<u64> + Into<u64>> Serialize
for Delegation<DID, V, C>
impl<DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec> Serialize for Delegation<DID, V, C>
where
Payload<DID>: TryFrom<Named<Ipld>>,
{
Expand All @@ -178,8 +174,8 @@ where
}
}

impl<'de, DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec + TryFrom<u64> + Into<u64>>
Deserialize<'de> for Delegation<DID, V, C>
impl<'de, DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec> Deserialize<'de>
for Delegation<DID, V, C>
where
Payload<DID>: TryFrom<Named<Ipld>>,
<Payload<DID> as TryFrom<Named<Ipld>>>::Error: std::fmt::Display,
Expand Down
10 changes: 3 additions & 7 deletions src/delegation/agent.rs
Expand Up @@ -23,7 +23,7 @@ pub struct Agent<
S: Store<DID, V, C>,
DID: Did + Clone = did::preset::Verifier,
V: varsig::Header<C> + Clone = varsig::header::Preset,
C: Codec + Into<u64> + TryFrom<u64> = varsig::encoding::Preset,
C: Codec = varsig::encoding::Preset,
> where
Ipld: Encode<C>,
Payload<DID>: TryFrom<Named<Ipld>>,
Expand All @@ -39,12 +39,8 @@ pub struct Agent<
_marker: PhantomData<(V, C)>,
}

impl<
S: Store<DID, V, C> + Clone,
DID: Did + Clone,
V: varsig::Header<C> + Clone,
C: Codec + TryFrom<u64> + Into<u64>,
> Agent<S, DID, V, C>
impl<S: Store<DID, V, C> + Clone, DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec>
Agent<S, DID, V, C>
where
Ipld: Encode<C>,
Payload<DID>: TryFrom<Named<Ipld>>,
Expand Down
23 changes: 7 additions & 16 deletions src/delegation/store/memory.rs
Expand Up @@ -78,7 +78,7 @@ use web_time::SystemTime;
pub struct MemoryStore<
DID: did::Did + Ord = did::preset::Verifier,
V: varsig::Header<C> = varsig::header::Preset,
C: Codec + TryFrom<u64> + Into<u64> = varsig::encoding::Preset,
C: Codec = varsig::encoding::Preset,
> {
inner: Arc<Mutex<MemoryStoreInner<DID, V, C>>>,
}
Expand All @@ -87,16 +87,14 @@ pub struct MemoryStore<
struct MemoryStoreInner<
DID: did::Did + Ord = did::preset::Verifier,
V: varsig::Header<C> = varsig::header::Preset,
C: Codec + TryFrom<u64> + Into<u64> = varsig::encoding::Preset,
C: Codec = varsig::encoding::Preset,
> {
ucans: BTreeMap<Cid, Arc<Delegation<DID, V, C>>>,
index: BTreeMap<Option<DID>, BTreeMap<DID, BTreeSet<Cid>>>,
revocations: BTreeSet<Cid>,
}

impl<DID: did::Did + Ord, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>>
MemoryStore<DID, V, C>
{
impl<DID: did::Did + Ord, V: varsig::Header<C>, C: Codec> MemoryStore<DID, V, C> {
pub fn new() -> Self {
Self::default()
}
Expand All @@ -120,19 +118,15 @@ impl<DID: did::Did + Ord, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u
}
}

impl<DID: did::Did + Ord, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>> Default
for MemoryStore<DID, V, C>
{
impl<DID: did::Did + Ord, V: varsig::Header<C>, C: Codec> Default for MemoryStore<DID, V, C> {
fn default() -> Self {
Self {
inner: Default::default(),
}
}
}

impl<DID: Did + Ord, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>> Default
for MemoryStoreInner<DID, V, C>
{
impl<DID: Did + Ord, V: varsig::Header<C>, C: Codec> Default for MemoryStoreInner<DID, V, C> {
fn default() -> Self {
MemoryStoreInner {
ucans: BTreeMap::new(),
Expand All @@ -143,11 +137,8 @@ impl<DID: Did + Ord, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>>
}

// FIXME check that UCAN is valid
impl<
DID: Did + Ord + Clone,
V: varsig::Header<Enc> + Clone,
Enc: Codec + TryFrom<u64> + Into<u64>,
> Store<DID, V, Enc> for MemoryStore<DID, V, Enc>
impl<DID: Did + Ord + Clone, V: varsig::Header<Enc> + Clone, Enc: Codec> Store<DID, V, Enc>
for MemoryStore<DID, V, Enc>
where
Named<Ipld>: From<delegation::Payload<DID>>,
delegation::Payload<DID>: TryFrom<Named<Ipld>>,
Expand Down
10 changes: 3 additions & 7 deletions src/delegation/store/traits.rs
Expand Up @@ -14,7 +14,7 @@ use std::{fmt::Debug, sync::Arc};
use thiserror::Error;
use web_time::SystemTime;

pub trait Store<DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec + TryFrom<u64> + Into<u64>>
pub trait Store<DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec>
where
Ipld: Encode<C>,
Payload<DID>: TryFrom<Named<Ipld>>,
Expand Down Expand Up @@ -89,12 +89,8 @@ where
}
}

impl<
T: Store<DID, V, C>,
DID: Did + Clone,
V: varsig::Header<C> + Clone,
C: Codec + TryFrom<u64> + Into<u64>,
> Store<DID, V, C> for &T
impl<T: Store<DID, V, C>, DID: Did + Clone, V: varsig::Header<C> + Clone, C: Codec> Store<DID, V, C>
for &T
where
Ipld: Encode<C>,
Payload<DID>: TryFrom<Named<Ipld>>,
Expand Down
22 changes: 9 additions & 13 deletions src/invocation.rs
Expand Up @@ -54,7 +54,7 @@ pub struct Invocation<
A,
DID: did::Did = did::preset::Verifier,
V: varsig::Header<C> = varsig::header::Preset,
C: Codec + TryFrom<u64> + Into<u64> = varsig::encoding::Preset,
C: Codec = varsig::encoding::Preset,
> {
pub varsig_header: V,
pub payload: Payload<A, DID>,
Expand All @@ -66,7 +66,7 @@ impl<
A: Clone + ToCommand + ParseAbility,
DID: Clone + did::Did,
V: Clone + varsig::Header<C>,
C: Codec + TryFrom<u64> + Into<u64>,
C: Codec,
> Encode<C> for Invocation<A, DID, V, C>
where
Ipld: Encode<C>,
Expand All @@ -79,12 +79,8 @@ where
}
}

impl<
A: Clone + ToCommand + ParseAbility,
DID: Did + Clone,
V: varsig::Header<C>,
C: Codec + TryFrom<u64> + Into<u64>,
> Invocation<A, DID, V, C>
impl<A: Clone + ToCommand + ParseAbility, DID: Did + Clone, V: varsig::Header<C>, C: Codec>
Invocation<A, DID, V, C>
where
Ipld: Encode<C>,
{
Expand Down Expand Up @@ -150,7 +146,7 @@ where
}
}

impl<A, DID: Did, V: varsig::Header<C>, C: Codec + TryFrom<u64> + Into<u64>> did::Verifiable<DID>
impl<A, DID: Did, V: varsig::Header<C>, C: Codec> did::Verifiable<DID>
for Invocation<A, DID, V, C>
{
fn verifier(&self) -> &DID {
Expand All @@ -162,7 +158,7 @@ impl<
A: Clone + ToCommand + ParseAbility,
DID: Did + Clone,
V: varsig::Header<C> + Clone,
C: Codec + TryFrom<u64> + Into<u64>,
C: Codec,
> From<Invocation<A, DID, V, C>> for Ipld
where
Named<Ipld>: From<A>,
Expand All @@ -177,7 +173,7 @@ impl<
A: Clone + ToCommand + ParseAbility,
DID: Did + Clone,
V: varsig::Header<C> + Clone,
C: Codec + TryFrom<u64> + Into<u64>,
C: Codec,
> Envelope for Invocation<A, DID, V, C>
where
Named<Ipld>: From<A>,
Expand Down Expand Up @@ -222,7 +218,7 @@ impl<
A: Clone + ToCommand + ParseAbility,
DID: Did + Clone,
V: varsig::Header<C> + Clone,
C: Codec + TryFrom<u64> + Into<u64>,
C: Codec,
> Serialize for Invocation<A, DID, V, C>
where
Named<Ipld>: From<A>,
Expand All @@ -241,7 +237,7 @@ impl<
A: Clone + ToCommand + ParseAbility,
DID: Did + Clone,
V: varsig::Header<C> + Clone,
C: Codec + TryFrom<u64> + Into<u64>,
C: Codec,
> Deserialize<'de> for Invocation<A, DID, V, C>
where
Named<Ipld>: From<A>,
Expand Down

0 comments on commit 7f680d3

Please sign in to comment.