Skip to content

Commit b5b99d1

Browse files
authored
Merge branch 'main' into createAccountEnhancement
2 parents 2ce139b + e8e288b commit b5b99d1

File tree

105 files changed

+2881
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+2881
-604
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resolver = "2"
66
cargo = { version = "0.84.0",features = ["vendored-openssl"] }
77
rsky-lexicon = {path = "rsky-lexicon", version = "0.2.3"}
88
rsky-identity = {path = "rsky-identity", version = "0.1.0"}
9-
rsky-crypto = {path = "rsky-crypto", version = "0.1.0"}
9+
rsky-crypto = {path = "rsky-crypto", version = "0.1.1"}
1010
rsky-syntax = {path = "rsky-syntax", version = "0.1.0"}
1111
rsky-common = {path = "rsky-common", version = "0.1.0"}
1212

rsky-crypto/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rsky-crypto"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Rudy Fraser <him@rudyfraser.com>"]
55
description = "Rust library providing basic cryptographic helpers as needed in atproto"
66
license = "Apache-2.0"
@@ -12,6 +12,6 @@ documentation = "https://docs.rs/rsky-crypto"
1212

1313
[dependencies]
1414
multibase = "0.9.1"
15-
secp256k1 = { version = "0.28.2", features = ["global-context", "serde", "rand", "hashes"] }
15+
secp256k1 = { version = "0.28.2", features = ["global-context", "serde", "rand", "hashes","rand-std"] }
1616
anyhow = "1.0.79"
1717
p256 = { version = "0.13.2", features = ["ecdsa","arithmetic","alloc"] }

rsky-crypto/src/utils.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::constants::{BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX};
22
use anyhow::{bail, Result};
3-
use multibase::{encode, Base};
3+
use multibase::decode;
4+
use secp256k1::rand::rngs::OsRng;
5+
use secp256k1::rand::RngCore;
46

57
pub fn extract_multikey(did: &String) -> Result<String> {
68
if !did.starts_with(DID_KEY_PREFIX) {
@@ -13,9 +15,16 @@ pub fn extract_prefixed_bytes(multikey: String) -> Result<Vec<u8>> {
1315
if !multikey.starts_with(BASE58_MULTIBASE_PREFIX) {
1416
bail!("Incorrect prefix for multikey: {multikey}")
1517
}
16-
Ok(encode(Base::Base58Btc, &multikey[BASE58_MULTIBASE_PREFIX.len()..]).into_bytes())
18+
let (_base, bytes) = decode(&multikey)?;
19+
Ok(bytes)
1720
}
1821

1922
pub fn has_prefix(bytes: &Vec<u8>, prefix: &Vec<u8>) -> bool {
2023
*prefix == bytes[0..prefix.len()]
2124
}
25+
26+
pub fn random_bytes(len: usize) -> Vec<u8> {
27+
let mut buf = vec![0u8; len];
28+
OsRng.fill_bytes(&mut buf);
29+
buf
30+
}

rsky-pds/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ async-recursion = "1.1.1"
7777
once_cell = "1.19.0"
7878
tracing = "0.1.41"
7979
tracing-subscriber = "0.3.19"
80+
async-stream = "0.3.5"
8081

8182

8283
[dependencies.rocket_sync_db_pools]

rsky-pds/src/apis/app/bsky/actor/get_preferences.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::apis::ApiError;
22
use crate::auth_verifier::AccessStandard;
3+
use crate::db::DbConn;
34
use crate::repo::aws::s3::S3BlobStore;
45
use crate::repo::ActorStore;
56
use anyhow::Result;
@@ -11,12 +12,14 @@ use rsky_lexicon::app::bsky::actor::{GetPreferencesOutput, RefPreferences};
1112
async fn inner_get_preferences(
1213
s3_config: &State<SdkConfig>,
1314
auth: AccessStandard,
15+
db: DbConn,
1416
) -> Result<GetPreferencesOutput> {
1517
let auth = auth.access.credentials.unwrap();
1618
let requester = auth.did.unwrap().clone();
1719
let actor_store = ActorStore::new(
1820
requester.clone(),
1921
S3BlobStore::new(requester.clone(), s3_config),
22+
db,
2023
);
2124
let preferences: Vec<RefPreferences> = actor_store
2225
.pref
@@ -28,15 +31,17 @@ async fn inner_get_preferences(
2831

2932
/// Get private preferences attached to the current account. Expected use is synchronization
3033
/// between multiple devices, and import/export during account migration. Requires auth.
34+
#[tracing::instrument(skip_all)]
3135
#[rocket::get("/xrpc/app.bsky.actor.getPreferences")]
3236
pub async fn get_preferences(
3337
s3_config: &State<SdkConfig>,
3438
auth: AccessStandard,
39+
db: DbConn,
3540
) -> Result<Json<GetPreferencesOutput>, ApiError> {
36-
match inner_get_preferences(s3_config, auth).await {
41+
match inner_get_preferences(s3_config, auth, db).await {
3742
Ok(res) => Ok(Json(res)),
3843
Err(error) => {
39-
eprintln!("@LOG: ERROR: {error}");
44+
tracing::error!("@LOG: ERROR: {error}");
4045
Err(ApiError::RuntimeError)
4146
}
4247
}

rsky-pds/src/apis/app/bsky/actor/get_profile.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::apis::ApiError;
22
use crate::auth_verifier::AccessStandard;
33
use crate::config::ServerConfig;
4+
use crate::db::DbConn;
45
use crate::read_after_write::types::LocalRecords;
56
use crate::read_after_write::util::{handle_read_after_write, ReadAfterWriteResponse};
67
use crate::read_after_write::viewer::LocalViewer;
@@ -20,6 +21,7 @@ pub async fn inner_get_profile(
2021
res: HandlerPipeThrough,
2122
s3_config: &State<SdkConfig>,
2223
state_local_viewer: &State<SharedLocalViewer>,
24+
db: DbConn,
2325
) -> Result<ReadAfterWriteResponse<ProfileViewDetailed>, ApiError> {
2426
let requester: Option<String> = match auth.access.credentials {
2527
None => None,
@@ -35,6 +37,7 @@ pub async fn inner_get_profile(
3537
get_profile_munge,
3638
s3_config,
3739
state_local_viewer,
40+
db,
3841
)
3942
.await?;
4043
Ok(read_afer_write_response)
@@ -44,6 +47,7 @@ pub async fn inner_get_profile(
4447

4548
/// Get detailed profile view of an actor. Does not require auth,
4649
/// but contains relevant metadata with auth.
50+
#[tracing::instrument(skip_all)]
4751
#[rocket::get("/xrpc/app.bsky.actor.getProfile?<actor>")]
4852
pub async fn get_profile(
4953
// Handle or DID of account to fetch profile of.
@@ -53,13 +57,16 @@ pub async fn get_profile(
5357
s3_config: &State<SdkConfig>,
5458
state_local_viewer: &State<SharedLocalViewer>,
5559
cfg: &State<ServerConfig>,
60+
db: DbConn,
5661
) -> Result<ReadAfterWriteResponse<ProfileViewDetailed>, ApiError> {
5762
match cfg.bsky_app_view {
5863
None => Err(ApiError::AccountNotFound),
59-
Some(_) => match inner_get_profile(actor, auth, res, s3_config, state_local_viewer).await {
60-
Ok(response) => Ok(response),
61-
Err(error) => Err(error),
62-
},
64+
Some(_) => {
65+
match inner_get_profile(actor, auth, res, s3_config, state_local_viewer, db).await {
66+
Ok(response) => Ok(response),
67+
Err(error) => Err(error),
68+
}
69+
}
6370
}
6471
}
6572

rsky-pds/src/apis/app/bsky/actor/get_profiles.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::apis::ApiError;
22
use crate::auth_verifier::AccessStandard;
33
use crate::config::ServerConfig;
4+
use crate::db::DbConn;
45
use crate::read_after_write::types::LocalRecords;
56
use crate::read_after_write::util::{handle_read_after_write, ReadAfterWriteResponse};
67
use crate::read_after_write::viewer::LocalViewer;
@@ -19,6 +20,7 @@ pub async fn inner_get_profiles(
1920
res: HandlerPipeThrough,
2021
s3_config: &State<SdkConfig>,
2122
state_local_viewer: &State<SharedLocalViewer>,
23+
db: DbConn,
2224
) -> Result<ReadAfterWriteResponse<GetProfilesOutput>, ApiError> {
2325
let requester: String = match auth.access.credentials {
2426
None => "".to_string(),
@@ -31,12 +33,14 @@ pub async fn inner_get_profiles(
3133
get_profiles_munge,
3234
s3_config,
3335
state_local_viewer,
36+
db,
3437
)
3538
.await?;
3639
Ok(read_afer_write_response)
3740
}
3841

3942
/// Get detailed profile views of multiple actors.
43+
#[tracing::instrument(skip_all)]
4044
#[rocket::get("/xrpc/app.bsky.actor.getProfiles?<actors>")]
4145
pub async fn get_profiles(
4246
actors: Vec<String>,
@@ -45,14 +49,16 @@ pub async fn get_profiles(
4549
s3_config: &State<SdkConfig>,
4650
state_local_viewer: &State<SharedLocalViewer>,
4751
cfg: &State<ServerConfig>,
52+
db: DbConn,
4853
) -> Result<ReadAfterWriteResponse<GetProfilesOutput>, ApiError> {
4954
match cfg.bsky_app_view {
5055
None => Err(ApiError::AccountNotFound),
51-
Some(_) => match inner_get_profiles(actors, auth, res, s3_config, state_local_viewer).await
52-
{
53-
Ok(response) => Ok(response),
54-
Err(error) => Err(error),
55-
},
56+
Some(_) => {
57+
match inner_get_profiles(actors, auth, res, s3_config, state_local_viewer, db).await {
58+
Ok(response) => Ok(response),
59+
Err(error) => Err(error),
60+
}
61+
}
5662
}
5763
}
5864

rsky-pds/src/apis/app/bsky/actor/put_preferences.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::apis::ApiError;
22
use crate::auth_verifier::AccessStandard;
3+
use crate::db::DbConn;
34
use crate::repo::aws::s3::S3BlobStore;
45
use crate::repo::ActorStore;
56
use anyhow::Result;
@@ -12,13 +13,15 @@ async fn inner_put_preferences(
1213
body: Json<PutPreferencesInput>,
1314
s3_config: &State<SdkConfig>,
1415
auth: AccessStandard,
16+
db: DbConn,
1517
) -> Result<(), ApiError> {
1618
let PutPreferencesInput { preferences } = body.into_inner();
1719
let auth = auth.access.credentials.unwrap();
1820
let requester = auth.did.unwrap().clone();
1921
let actor_store = ActorStore::new(
2022
requester.clone(),
2123
S3BlobStore::new(requester.clone(), s3_config),
24+
db,
2225
);
2326
actor_store
2427
.pref
@@ -27,6 +30,7 @@ async fn inner_put_preferences(
2730
Ok(())
2831
}
2932

33+
#[tracing::instrument(skip_all)]
3034
#[rocket::post(
3135
"/xrpc/app.bsky.actor.putPreferences",
3236
format = "json",
@@ -36,8 +40,9 @@ pub async fn put_preferences(
3640
body: Json<PutPreferencesInput>,
3741
s3_config: &State<SdkConfig>,
3842
auth: AccessStandard,
43+
db: DbConn,
3944
) -> Result<(), ApiError> {
40-
match inner_put_preferences(body, s3_config, auth).await {
45+
match inner_put_preferences(body, s3_config, auth, db).await {
4146
Ok(_) => Ok(()),
4247
Err(error) => Err(error),
4348
}

rsky-pds/src/apis/app/bsky/feed/get_actor_likes.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::apis::ApiError;
22
use crate::auth_verifier::AccessStandard;
33
use crate::config::ServerConfig;
4+
use crate::db::DbConn;
45
use crate::read_after_write::types::LocalRecords;
56
use crate::read_after_write::util::{handle_read_after_write, ReadAfterWriteResponse};
67
use crate::read_after_write::viewer::LocalViewer;
@@ -21,6 +22,7 @@ pub async fn inner_get_actor_likes(
2122
res: HandlerPipeThrough,
2223
s3_config: &State<SdkConfig>,
2324
state_local_viewer: &State<SharedLocalViewer>,
25+
db: DbConn,
2426
) -> Result<ReadAfterWriteResponse<AuthorFeed>> {
2527
let requester: Option<String> = match auth.access.credentials {
2628
None => None,
@@ -36,6 +38,7 @@ pub async fn inner_get_actor_likes(
3638
get_author_munge,
3739
s3_config,
3840
state_local_viewer,
41+
db,
3942
)
4043
.await?;
4144
Ok(read_afer_write_response)
@@ -44,6 +47,7 @@ pub async fn inner_get_actor_likes(
4447
}
4548

4649
/// Get a list of posts liked by an actor. Does not require auth.
50+
#[tracing::instrument(skip_all)]
4751
#[rocket::get("/xrpc/app.bsky.feed.getActorLikes?<actor>&<limit>&<cursor>")]
4852
pub async fn get_actor_likes(
4953
actor: String,
@@ -54,6 +58,7 @@ pub async fn get_actor_likes(
5458
s3_config: &State<SdkConfig>,
5559
state_local_viewer: &State<SharedLocalViewer>,
5660
cfg: &State<ServerConfig>,
61+
db: DbConn,
5762
) -> Result<ReadAfterWriteResponse<AuthorFeed>, ApiError> {
5863
if let Some(limit) = limit {
5964
if limit > 100 {
@@ -70,12 +75,13 @@ pub async fn get_actor_likes(
7075
res,
7176
s3_config,
7277
state_local_viewer,
78+
db,
7379
)
7480
.await
7581
{
7682
Ok(response) => Ok(response),
7783
Err(error) => {
78-
eprintln!("{error}");
84+
tracing::error!("{error}");
7985
Err(ApiError::RuntimeError)
8086
}
8187
},

rsky-pds/src/apis/app/bsky/feed/get_author_feed.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::apis::ApiError;
22
use crate::auth_verifier::AccessStandard;
33
use crate::config::ServerConfig;
4+
use crate::db::DbConn;
45
use crate::read_after_write::types::LocalRecords;
56
use crate::read_after_write::util::{handle_read_after_write, ReadAfterWriteResponse};
67
use crate::read_after_write::viewer::LocalViewer;
@@ -23,6 +24,7 @@ pub async fn inner_get_author_feed(
2324
res: HandlerPipeThrough,
2425
s3_config: &State<SdkConfig>,
2526
state_local_viewer: &State<SharedLocalViewer>,
27+
db: DbConn,
2628
) -> Result<ReadAfterWriteResponse<AuthorFeed>> {
2729
let requester: Option<String> = match auth.access.credentials {
2830
None => None,
@@ -38,6 +40,7 @@ pub async fn inner_get_author_feed(
3840
get_author_munge,
3941
s3_config,
4042
state_local_viewer,
43+
db,
4144
)
4245
.await?;
4346
Ok(read_afer_write_response)
@@ -46,6 +49,7 @@ pub async fn inner_get_author_feed(
4649
}
4750

4851
/// Get a view of an actor's 'author feed' (post and reposts by the author). Does not require auth.
52+
#[tracing::instrument(skip_all)]
4953
#[rocket::get("/xrpc/app.bsky.feed.getAuthorFeed?<actor>&<limit>&<cursor>&<filter>")]
5054
pub async fn get_author_feed(
5155
actor: String,
@@ -57,6 +61,7 @@ pub async fn get_author_feed(
5761
s3_config: &State<SdkConfig>,
5862
state_local_viewer: &State<SharedLocalViewer>,
5963
cfg: &State<ServerConfig>,
64+
db: DbConn,
6065
) -> Result<ReadAfterWriteResponse<AuthorFeed>, ApiError> {
6166
if let Some(limit) = limit {
6267
if limit > 100 {
@@ -97,6 +102,7 @@ pub async fn get_author_feed(
97102
res,
98103
s3_config,
99104
state_local_viewer,
105+
db,
100106
)
101107
.await
102108
{

0 commit comments

Comments
 (0)