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

feat: Promote NsRecord into a core object #399

Merged
merged 1 commit into from
May 23, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void = { version = "1" }
wnfs-namefilter = { version = "0.1.20" }
strum = { version = "0.24" }
strum_macros = { version = "0.24" }

serde = { version = "^1" }
serde_json = { version = "^1" }

[profile.release]
opt-level = 'z'
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ anyhow = "^1"
thiserror = { workspace = true }
cid = { workspace = true }
url = "^2"
serde = "^1"
serde = { workspace = true }
serde_urlencoded = "~0.7"
tracing = { workspace = true }
noosphere-core = { version = "0.11.0", path = "../noosphere-core" }
Expand Down
4 changes: 2 additions & 2 deletions rust/noosphere-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ ucan-key-support = { workspace = true }
cid = { workspace = true }
subtext = "0.3.2"

serde = "^1"
serde_json = "^1"
serde = { workspace = true }
serde_json = { workspace = true }
libipld-core = { workspace = true }
libipld-cbor = { workspace = true }

Expand Down
4 changes: 2 additions & 2 deletions rust/noosphere-collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ anyhow = "^1"
sha2 = "0.10"
cid = { workspace = true }
forest_hash_utils = "0.1.0"
serde = "^1"
serde = { workspace = true }
serde_bytes = "0.11"
serde_ipld_dagcbor = "0.2"
byteorder = "^1.4"
Expand All @@ -48,4 +48,4 @@ tokio = { version = "^1", features = ["full"] }
wasm-bindgen-test = "0.3"

[features]
identity = []
identity = []
3 changes: 2 additions & 1 deletion rust/noosphere-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ anyhow = "^1"
fastcdc = "3"
futures = "~0.3"
fvm_ipld_amt = "~0.5"
serde = "^1"
serde = { workspace = true }
byteorder = "^1.4"
base64 = "0.21"
ed25519-zebra = "^3"
Expand All @@ -56,6 +56,7 @@ ucan-key-support = { workspace = true }
[dev-dependencies]
wasm-bindgen-test = "~0.3"
serde_bytes = "~0.11"
serde_json = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "^1", features = ["full"] }
Expand Down
33 changes: 32 additions & 1 deletion rust/noosphere-core/src/authority/capability.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{anyhow, Result};
use ucan::capability::{Action, CapabilitySemantics, Scope};
use ucan::capability::{Action, Capability, CapabilitySemantics, Resource, Scope, With};
use url::Url;

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
Expand Down Expand Up @@ -80,3 +80,34 @@ pub struct SphereSemantics {}
impl CapabilitySemantics<SphereReference, SphereAction> for SphereSemantics {}

pub const SPHERE_SEMANTICS: SphereSemantics = SphereSemantics {};

/// Generates a [Capability] struct representing permissions in a [LinkRecord].
///
/// ```
/// use noosphere_core::{authority::{generate_capability, SphereAction, SphereReference}};
/// use ucan::capability::{Capability, Resource, With};
///
/// let identity = "did:key:z6MkoE19WHXJzpLqkxbGP7uXdJX38sWZNUWwyjcuCmjhPpUP";
/// let expected_capability = Capability {
/// with: With::Resource {
/// kind: Resource::Scoped(SphereReference {
/// did: identity.to_owned(),
/// }),
/// },
/// can: SphereAction::Publish,
/// };
/// assert_eq!(generate_capability(&identity, SphereAction::Publish), expected_capability);
/// ```
pub fn generate_capability(
identity: &str,
action: SphereAction,
) -> Capability<SphereReference, SphereAction> {
Capability {
with: With::Resource {
kind: Resource::Scoped(SphereReference {
did: identity.to_owned(),
}),
},
can: action,
}
}
Loading