aboutsummaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-07 00:44:35 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-11-07 00:44:35 -0800
commit73bb6f114d3fe9233af4f9ab91c8fc2b09b3c6c0 (patch)
treee04adc0818f9089dc727af065683b9c110208643 /adenosine-pds/src
parent13b77ec75c5018f17048e2712ca83da3b4bb82dc (diff)
downloadadenosine-73bb6f114d3fe9233af4f9ab91c8fc2b09b3c6c0.tar.gz
adenosine-73bb6f114d3fe9233af4f9ab91c8fc2b09b3c6c0.zip
pds: update upstream lexicon details
Diffstat (limited to 'adenosine-pds/src')
-rw-r--r--adenosine-pds/src/atp_db.sql6
-rw-r--r--adenosine-pds/src/db.rs22
-rw-r--r--adenosine-pds/src/lib.rs45
-rw-r--r--adenosine-pds/src/models.rs4
4 files changed, 39 insertions, 38 deletions
diff --git a/adenosine-pds/src/atp_db.sql b/adenosine-pds/src/atp_db.sql
index 350c9ef..b356abc 100644
--- a/adenosine-pds/src/atp_db.sql
+++ b/adenosine-pds/src/atp_db.sql
@@ -3,18 +3,18 @@
CREATE TABLE account(
did TEXT PRIMARY KEY NOT NULL,
- username TEXT NOT NULL,
+ handle TEXT NOT NULL,
email TEXT NOT NULL,
password_bcrypt TEXT NOT NULL,
recovery_pubkey TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT ( DATETIME('now') )
);
-CREATE UNIQUE INDEX account_username_uniq_idx on account(lower(username));
+CREATE UNIQUE INDEX account_handle_uniq_idx on account(lower(handle));
CREATE UNIQUE INDEX account_email_uniq_idx on account(lower(email));
CREATE TABLE did_doc(
did TEXT PRIMARY KEY NOT NULL,
- -- TODO: username TEXT NOT NULL,
+ -- TODO: handle TEXT NOT NULL,
doc_json TEXT NOT NULL,
indexed_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT ( DATETIME('now') )
);
diff --git a/adenosine-pds/src/db.rs b/adenosine-pds/src/db.rs
index 5f185c8..2249637 100644
--- a/adenosine-pds/src/db.rs
+++ b/adenosine-pds/src/db.rs
@@ -63,19 +63,19 @@ impl AtpDatabase {
Ok(AtpDatabase { conn })
}
- /// Quick check if an account already exists for given username or email
- pub fn account_exists(&mut self, username: &str, email: &str) -> Result<bool> {
+ /// Quick check if an account already exists for given handle or email
+ pub fn account_exists(&mut self, handle: &str, email: &str) -> Result<bool> {
let mut stmt = self
.conn
- .prepare_cached("SELECT COUNT(*) FROM account WHERE username = $1 OR email = $2")?;
- let count: i32 = stmt.query_row(params!(username, email), |row| row.get(0))?;
+ .prepare_cached("SELECT COUNT(*) FROM account WHERE handle = $1 OR email = $2")?;
+ let count: i32 = stmt.query_row(params!(handle, email), |row| row.get(0))?;
Ok(count > 0)
}
pub fn create_account(
&mut self,
did: &Did,
- username: &str,
+ handle: &str,
password: &str,
email: &str,
recovery_pubkey: &str,
@@ -83,10 +83,10 @@ impl AtpDatabase {
debug!("bcrypt hashing password (can be slow)...");
let password_bcrypt = bcrypt::hash(password, BCRYPT_COST)?;
let mut stmt = self.conn.prepare_cached(
- "INSERT INTO account (username, password_bcrypt, email, did, recovery_pubkey) VALUES (?1, ?2, ?3, ?4, ?5)",
+ "INSERT INTO account (handle, password_bcrypt, email, did, recovery_pubkey) VALUES (?1, ?2, ?3, ?4, ?5)",
)?;
stmt.execute(params!(
- username,
+ handle,
password_bcrypt,
email,
did.to_string(),
@@ -98,15 +98,15 @@ impl AtpDatabase {
/// Returns a JWT session token
pub fn create_session(
&mut self,
- username: &str,
+ handle: &str,
password: &str,
keypair: &KeyPair,
) -> Result<AtpSession> {
let mut stmt = self
.conn
- .prepare_cached("SELECT did, password_bcrypt FROM account WHERE username = ?1")?;
+ .prepare_cached("SELECT did, password_bcrypt FROM account WHERE handle = ?1")?;
let (did_col, password_bcrypt): (String, String) =
- stmt.query_row(params!(username), |row| Ok((row.get(0)?, row.get(1)?)))?;
+ stmt.query_row(params!(handle), |row| Ok((row.get(0)?, row.get(1)?)))?;
if !bcrypt::verify(password, &password_bcrypt)? {
return Err(anyhow!("password did not match"));
}
@@ -118,7 +118,7 @@ impl AtpDatabase {
stmt.execute(params!(did.to_string(), jwt))?;
Ok(AtpSession {
did: did.to_string(),
- name: username.to_string(),
+ name: handle.to_string(),
accessJwt: jwt.to_string(),
refreshJwt: jwt,
})
diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs
index dc34d09..a11b862 100644
--- a/adenosine-pds/src/lib.rs
+++ b/adenosine-pds/src/lib.rs
@@ -20,6 +20,7 @@ pub mod mst;
mod repo;
mod ucan_p256;
mod vendored;
+mod web;
pub use car::{load_car_to_blockstore, load_car_to_sqlite};
pub use crypto::{KeyPair, PubKey};
@@ -201,7 +202,7 @@ fn xrpc_get_handler(
request: &Request,
) -> Result<serde_json::Value> {
match method {
- "com.atproto.getAccountsConfig" => {
+ "com.atproto.server.getAccountsConfig" => {
Ok(json!({"availableUserDomains": ["test"], "inviteCodeRequired": false}))
}
"com.atproto.repoGetRecord" => {
@@ -220,7 +221,7 @@ fn xrpc_get_handler(
Err(e) => Err(e),
}
}
- "com.atproto.syncGetRoot" => {
+ "com.atproto.sync.getRoot" => {
let did = Did::from_str(&xrpc_required_param(request, "did")?)?;
let mut srv = srv.lock().expect("service mutex");
srv.repo
@@ -228,7 +229,7 @@ fn xrpc_get_handler(
.map(|v| json!({ "root": v }))
.ok_or(XrpcError::NotFound(format!("no repository found for DID: {}", did)).into())
}
- "com.atproto.repoListRecords" => {
+ "com.atproto.repo.listRecords" => {
// TODO: limit, before, after, tid, reverse
// TODO: handle non-DID 'user'
// TODO: limit result set size
@@ -253,15 +254,15 @@ fn xrpc_get_handler(
}
Ok(json!({ "records": record_list }))
}
- "com.atproto.repoDescribe" => {
+ "com.atproto.repo.describe" => {
let did = Did::from_str(&xrpc_required_param(request, "user")?)?;
- // TODO: resolve username?
- let username = did.to_string();
+ // TODO: resolve handle?
+ let handle = did.to_string();
let mut srv = srv.lock().expect("service mutex");
let did_doc = srv.atp_db.get_did_doc(&did)?;
let collections: Vec<String> = srv.repo.collections(&did)?;
let desc = RepoDescribe {
- name: username,
+ name: handle,
did: did.to_string(),
didDoc: did_doc,
collections: collections,
@@ -282,25 +283,25 @@ fn xrpc_post_handler(
request: &Request,
) -> Result<serde_json::Value> {
match method {
- "com.atproto.createAccount" => {
+ "com.atproto.account.create" => {
// validate account request
let req: AccountRequest = rouille::input::json_input(request)
.map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {}", e)))?;
- // TODO: validate username, email, recoverykey
+ // TODO: validate handle, email, recoverykey
// check if account already exists (fast path, also confirmed by database schema)
let mut srv = srv.lock().unwrap();
- if srv.atp_db.account_exists(&req.username, &req.email)? {
+ if srv.atp_db.account_exists(&req.handle, &req.email)? {
Err(XrpcError::BadRequest(
- "username or email already exists".to_string(),
+ "handle or email already exists".to_string(),
))?;
};
- debug!("trying to create new account: {}", &req.username);
+ debug!("trying to create new account: {}", &req.handle);
// generate DID
let create_op = did::CreateOp::new(
- req.username.clone(),
+ req.handle.clone(),
srv.pds_public_url.clone(),
&srv.pds_keypair,
req.recoveryKey.clone(),
@@ -315,7 +316,7 @@ fn xrpc_post_handler(
.unwrap_or(srv.pds_keypair.pubkey().to_did_key());
srv.atp_db.create_account(
&did,
- &req.username,
+ &req.handle,
&req.password,
&req.email,
&recovery_key,
@@ -333,21 +334,21 @@ fn xrpc_post_handler(
let keypair = srv.pds_keypair.clone();
let sess = srv
.atp_db
- .create_session(&req.username, &req.password, &keypair)?;
+ .create_session(&req.handle, &req.password, &keypair)?;
Ok(json!(sess))
}
- "com.atproto.createSession" => {
+ "com.atproto.session.create" => {
let req: SessionRequest = rouille::input::json_input(request)
.map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {}", e)))?;
let mut srv = srv.lock().unwrap();
let keypair = srv.pds_keypair.clone();
Ok(json!(srv.atp_db.create_session(
- &req.username,
+ &req.handle,
&req.password,
&keypair
)?))
}
- "com.atproto.deleteSession" => {
+ "com.atproto.session.delete" => {
let mut srv = srv.lock().unwrap();
let _did = xrpc_check_auth_header(&mut srv, request, None)?;
let header = request
@@ -364,7 +365,7 @@ fn xrpc_post_handler(
};
Ok(json!({}))
}
- "com.atproto.repoBatchWrite" => {
+ "com.atproto.repo.batchWrite" => {
let batch: RepoBatchWriteBody = rouille::input::json_input(request)?;
// TODO: validate edits against schemas
let did = Did::from_str(&xrpc_required_param(request, "did")?)?;
@@ -400,7 +401,7 @@ fn xrpc_post_handler(
// TODO: next handle updates to database
Ok(json!({}))
}
- "com.atproto.repoCreateRecord" => {
+ "com.atproto.repo.createRecord" => {
// TODO: validate edits against schemas
let did = Did::from_str(&xrpc_required_param(request, "did")?)?;
let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?;
@@ -417,7 +418,7 @@ fn xrpc_post_handler(
// TODO: next handle updates to database
Ok(json!({}))
}
- "com.atproto.repoPutRecord" => {
+ "com.atproto.repo.putRecord" => {
// TODO: validate edits against schemas
let did = Did::from_str(&xrpc_required_param(request, "did")?)?;
let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?;
@@ -436,7 +437,7 @@ fn xrpc_post_handler(
// TODO: next handle updates to database
Ok(json!({}))
}
- "com.atproto.repoDeleteRecord" => {
+ "com.atproto.repo.deleteRecord" => {
let did = Did::from_str(&xrpc_required_param(request, "did")?)?;
let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?;
let tid = Tid::from_str(&xrpc_required_param(request, "rkey")?)?;
diff --git a/adenosine-pds/src/models.rs b/adenosine-pds/src/models.rs
index 97705af..f172819 100644
--- a/adenosine-pds/src/models.rs
+++ b/adenosine-pds/src/models.rs
@@ -2,7 +2,7 @@
#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
pub struct AccountRequest {
pub email: String,
- pub username: String,
+ pub handle: String,
pub password: String,
pub inviteCode: Option<String>,
pub recoveryKey: Option<String>,
@@ -11,7 +11,7 @@ pub struct AccountRequest {
#[allow(non_snake_case)]
#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
pub struct SessionRequest {
- pub username: String,
+ pub handle: String,
pub password: String,
}