-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: libs #166
Draft
sugyan
wants to merge
17
commits into
main
Choose a base branch
from
feature/libs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: libs #166
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
07582fa
Add common_web/did_doc
sugyan d1d114d
Add identity, implement web-resolver
sugyan 7761afa
Implement plc_resolver, add tests
sugyan 8a92b2d
WIP: Add crypto
sugyan f53b03d
Implement format_did_key for Secp256k1
sugyan 59bb483
Implement format_did_key for P256
sugyan 817baab
Refactor crypto/algorithm
sugyan d64fcac
Separate crypto package
sugyan 19492c1
Fix workflows
sugyan 1cb62e7
Remove crypto from libs
sugyan 30faf8e
Implement crypto/keypair
sugyan bf6ee07
Update crypto/keypair
sugyan 5e256e5
Add crypto/verify, Update README
sugyan 2d372e3
Add tests
sugyan d236db0
Implement all tests for crypto
sugyan a435510
Add crypto/encoding, move logic and tests
sugyan 438f001
Update documents
sugyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Libs | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build | ||
run: | | ||
cargo build -p atrium-libs --verbose | ||
cargo build -p atrium-libs --verbose --features common-web | ||
cargo build -p atrium-libs --verbose --features identity | ||
cargo build -p atrium-libs --verbose --all-features | ||
- name: Run tests | ||
run: | | ||
cargo test -p atrium-libs --lib | ||
cargo test -p atrium-libs --lib --all-features |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "atrium-libs" | ||
version = "0.1.0" | ||
authors = ["sugyan <[email protected]>"] | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
description = "A collection of libraries for AT Protocol" | ||
readme = "README.md" | ||
repository.workspace = true | ||
license.workspace = true | ||
keywords.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-trait = { workspace = true, optional = true } | ||
serde = { workspace = true, optional = true } | ||
serde_json = { workspace = true, optional = true } | ||
thiserror = { workspace = true, optional = true } | ||
url = { workspace = true, optional = true } | ||
urlencoding = { workspace = true, optional = true } | ||
|
||
[dev-dependencies] | ||
mockito = { workspace = true } | ||
reqwest = { workspace = true } | ||
serde_json = { workspace = true } | ||
tokio = { workspace = true, features = ["macros"] } | ||
|
||
[features] | ||
default = [] | ||
common-web = ["serde/derive"] | ||
identity = ["common-web", "async-trait", "serde_json", "thiserror", "url", "urlencoding"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod did_doc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//! Definitions for DID document types. | ||
//! https://atproto.com/specs/did#did-documents | ||
|
||
/// A DID document, containing information associated with the DID | ||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct DidDocument { | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[serde(rename = "@context")] | ||
pub context: Option<Vec<String>>, | ||
pub id: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub also_known_as: Option<Vec<String>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub verification_method: Option<Vec<VerificationMethod>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub service: Option<Vec<Service>>, | ||
} | ||
|
||
/// The public signing key for the account | ||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct VerificationMethod { | ||
pub id: String, | ||
pub r#type: String, | ||
pub controller: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub public_key_multibase: Option<String>, | ||
} | ||
|
||
/// The PDS service network location for the account | ||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Service { | ||
pub id: String, | ||
pub r#type: String, | ||
pub service_endpoint: String, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
const DID_DOC_JSON: &str = r##"{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1","https://w3id.org/security/suites/secp256k1-2019/v1"],"id":"did:plc:4ee6oesrsbtmuln4gqsqf6fp","alsoKnownAs":["at://sugyan.com"],"verificationMethod":[{"id":"did:plc:4ee6oesrsbtmuln4gqsqf6fp#atproto","type":"Multikey","controller":"did:plc:4ee6oesrsbtmuln4gqsqf6fp","publicKeyMultibase":"zQ3shnw8ChQwGUE6gMghuvn5g7Q9YVej1MUJENqMsLmxZwRSz"}],"service":[{"id":"#atproto_pds","type":"AtprotoPersonalDataServer","serviceEndpoint":"https://puffball.us-east.host.bsky.network"}]}"##; | ||
|
||
fn did_doc_example() -> DidDocument { | ||
DidDocument { | ||
context: Some(vec![ | ||
String::from("https://www.w3.org/ns/did/v1"), | ||
String::from("https://w3id.org/security/multikey/v1"), | ||
String::from("https://w3id.org/security/suites/secp256k1-2019/v1"), | ||
]), | ||
id: String::from("did:plc:4ee6oesrsbtmuln4gqsqf6fp"), | ||
also_known_as: Some(vec![String::from("at://sugyan.com")]), | ||
verification_method: Some(vec![VerificationMethod { | ||
id: String::from("did:plc:4ee6oesrsbtmuln4gqsqf6fp#atproto"), | ||
r#type: String::from("Multikey"), | ||
controller: String::from("did:plc:4ee6oesrsbtmuln4gqsqf6fp"), | ||
public_key_multibase: Some(String::from( | ||
"zQ3shnw8ChQwGUE6gMghuvn5g7Q9YVej1MUJENqMsLmxZwRSz", | ||
)), | ||
}]), | ||
service: Some(vec![Service { | ||
id: String::from("#atproto_pds"), | ||
r#type: String::from("AtprotoPersonalDataServer"), | ||
service_endpoint: String::from("https://puffball.us-east.host.bsky.network"), | ||
}]), | ||
} | ||
} | ||
|
||
#[test] | ||
fn serialize_did_doc() { | ||
let result = | ||
serde_json::to_string(&did_doc_example()).expect("serialization should succeed"); | ||
assert_eq!(result, DID_DOC_JSON); | ||
} | ||
|
||
#[test] | ||
fn deserialize_did_doc() { | ||
let result = serde_json::from_str::<DidDocument>(DID_DOC_JSON) | ||
.expect("deserialization should succeed"); | ||
assert_eq!(result, did_doc_example()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
//! A library for decentralized identities in [atproto](https://atproto.com) using DIDs and handles | ||
pub mod did; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::common_web::did_doc::DidDocument; | ||
pub mod did_resolver; | ||
mod error; | ||
mod plc_resolver; | ||
mod web_resolver; | ||
|
||
use self::error::{Error, Result}; | ||
use async_trait::async_trait; | ||
|
||
#[async_trait] | ||
pub trait Fetch { | ||
async fn fetch( | ||
url: &str, | ||
timeout: Option<u64>, | ||
) -> std::result::Result<Option<Vec<u8>>, Box<dyn std::error::Error + Send + Sync + 'static>>; | ||
} | ||
|
||
#[async_trait] | ||
pub trait Resolve { | ||
async fn resolve_no_check(&self, did: &str) -> Result<Option<Vec<u8>>>; | ||
async fn resolve_no_cache(&self, did: &str) -> Result<Option<DidDocument>> { | ||
if let Some(got) = self.resolve_no_check(did).await? { | ||
Ok(serde_json::from_slice(&got)?) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
async fn resolve(&self, did: &str, force_refresh: bool) -> Result<Option<DidDocument>> { | ||
// TODO: from cache | ||
if let Some(got) = self.resolve_no_cache(did).await? { | ||
// TODO: store in cache | ||
Ok(Some(got)) | ||
} else { | ||
// TODO: clear cache | ||
Ok(None) | ||
} | ||
} | ||
async fn ensure_resolve(&self, did: &str, force_refresh: bool) -> Result<DidDocument> { | ||
self.resolve(did, force_refresh) | ||
.await? | ||
.ok_or_else(|| Error::DidNotFound(did.to_string())) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These types already exist in
atrium_api::did_doc
(and look almost identical, other than missing thecontext
field onDidDocument
). Is the plan to move these types out ofatrium-api
, or is this just a temporary duplication as part of figuring out whereatrium-libs
sits in the crate dependency tree?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look!
Yes, currently I am thinking of removing
atrium_api::did_doc
and referencingcommon_web::did_doc
from the api by adding these new libs.