Skip to content

Commit ccd5fe6

Browse files
authored
Revert "fix(cli,relay): resolve agents by verified owner" (#3168)
Reverts #2615
1 parent 4597ad7 commit ccd5fe6

8 files changed

Lines changed: 9 additions & 568 deletions

File tree

‎crates/buzz-cli/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ buzz reactions get --event <event-id>
5656
buzz users get # your own profile
5757
buzz users get --pubkey <hex> # single user
5858
buzz users get --pubkey <hex> --pubkey <hex> # batch (max 200)
59-
buzz users get --name Honey --owner me # exact-name lookup scoped to your verified owner
6059
buzz users set-presence --status online
6160

6261
# DMs

‎crates/buzz-cli/src/commands/users.rs‎

Lines changed: 7 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use nostr::PublicKey;
2-
31
use crate::client::{normalize_write_response, BuzzClient};
42
use crate::error::CliError;
53
use crate::validate::validate_hex64;
@@ -15,7 +13,6 @@ pub async fn cmd_get_users(
1513
client: &BuzzClient,
1614
pubkeys: &[String],
1715
name: Option<&str>,
18-
owner: Option<&str>,
1916
format: &crate::OutputFormat,
2017
) -> Result<(), CliError> {
2118
if let Some(query) = name {
@@ -24,7 +21,7 @@ pub async fn cmd_get_users(
2421
"--name and --pubkey are mutually exclusive".into(),
2522
));
2623
}
27-
return search_by_name(client, query, owner, format).await;
24+
return search_by_name(client, query, format).await;
2825
}
2926

3027
for pk in pubkeys {
@@ -41,18 +38,12 @@ pub async fn cmd_get_users(
4138
pubkeys.iter().map(|s| s.as_str()).collect()
4239
};
4340

44-
let owner = resolve_owner(client, owner)?;
4541
let filter = serde_json::json!({
4642
"kinds": [0],
4743
"authors": authors,
48-
"limit": authors.len(),
49-
"include_agent_owner": true,
50-
"agent_owner": owner,
44+
"limit": authors.len()
5145
});
5246
let resp = client.query(&filter).await?;
53-
let my_owner_pubkey = client
54-
.auth_tag_owner_hex()
55-
.unwrap_or_else(|| client.keys().public_key().to_hex());
5647
let events: Vec<serde_json::Value> = serde_json::from_str(&resp).unwrap_or_default();
5748
let profiles: Vec<serde_json::Value> = events
5849
.iter()
@@ -64,7 +55,6 @@ pub async fn cmd_get_users(
6455
"pubkey".to_string(),
6556
serde_json::json!(e.get("pubkey").and_then(|v| v.as_str()).unwrap_or("")),
6657
);
67-
copy_owner_fields(e, obj, &my_owner_pubkey);
6858
}
6959
Some(profile)
7060
})
@@ -76,9 +66,6 @@ pub async fn cmd_get_users(
7666
.map(|p| serde_json::json!({
7767
"pubkey": p.get("pubkey").cloned().unwrap_or_default(),
7868
"display_name": p.get("display_name").or_else(|| p.get("name")).cloned().unwrap_or_default(),
79-
"owner_pubkey": p.get("owner_pubkey").cloned().unwrap_or_default(),
80-
"owner_display_name": p.get("owner_display_name").cloned().unwrap_or_default(),
81-
"owned_by_me": p.get("owned_by_me").cloned().unwrap_or_default(),
8269
}))
8370
.collect();
8471
serde_json::to_string(&compact).unwrap_or_default()
@@ -89,70 +76,23 @@ pub async fn cmd_get_users(
8976
Ok(())
9077
}
9178

92-
fn copy_owner_fields(
93-
event: &serde_json::Value,
94-
profile: &mut serde_json::Map<String, serde_json::Value>,
95-
my_owner_pubkey: &str,
96-
) {
97-
if let Some(value) = event.get("agent_owner_pubkey") {
98-
profile.insert("owner_pubkey".to_string(), value.clone());
99-
}
100-
if let Some(value) = event.get("agent_owner_display_name") {
101-
profile.insert("owner_display_name".to_string(), value.clone());
102-
}
103-
if let Some(owner) = event
104-
.get("agent_owner_pubkey")
105-
.and_then(|value| value.as_str())
106-
{
107-
profile.insert(
108-
"owned_by_me".to_string(),
109-
serde_json::json!(owner == my_owner_pubkey),
110-
);
111-
}
112-
}
113-
114-
fn resolve_owner(client: &BuzzClient, owner: Option<&str>) -> Result<Option<String>, CliError> {
115-
owner
116-
.map(|owner| {
117-
if owner == "me" {
118-
Ok(client
119-
.auth_tag_owner_hex()
120-
.unwrap_or_else(|| client.keys().public_key().to_hex()))
121-
} else {
122-
PublicKey::parse(owner)
123-
.map(|pubkey| pubkey.to_hex())
124-
.map_err(|e| {
125-
CliError::Usage(format!("--owner must be `me`, a pubkey, or npub: {e}"))
126-
})
127-
}
128-
})
129-
.transpose()
130-
}
131-
13279
/// Search for users by display name via NIP-50 full-text search on kind:0 profiles.
13380
/// Returns [] if the relay does not implement NIP-50 search.
13481
async fn search_by_name(
13582
client: &BuzzClient,
13683
query: &str,
137-
owner: Option<&str>,
13884
format: &crate::OutputFormat,
13985
) -> Result<(), CliError> {
14086
if query.trim().is_empty() {
14187
return Err(CliError::Usage("--name cannot be empty".into()));
14288
}
14389

144-
let owner = resolve_owner(client, owner)?;
14590
let filter = serde_json::json!({
14691
"kinds": [0],
14792
"search": query,
148-
"limit": 100,
149-
"include_agent_owner": true,
150-
"agent_owner": owner,
93+
"limit": 100
15194
});
15295
let raw = client.query(&filter).await?;
153-
let my_owner_pubkey = client
154-
.auth_tag_owner_hex()
155-
.unwrap_or_else(|| client.keys().public_key().to_hex());
15696

15797
// Parse and filter client-side for case-insensitive substring match
15898
// on display_name or name fields (NIP-50 may return broader matches).
@@ -186,7 +126,6 @@ async fn search_by_name(
186126
"pubkey".to_string(),
187127
serde_json::json!(event.get("pubkey").and_then(|v| v.as_str()).unwrap_or("")),
188128
);
189-
copy_owner_fields(event, obj, &my_owner_pubkey);
190129
}
191130
Some(profile)
192131
})
@@ -198,9 +137,6 @@ async fn search_by_name(
198137
.map(|p| serde_json::json!({
199138
"pubkey": p.get("pubkey").cloned().unwrap_or_default(),
200139
"display_name": p.get("display_name").or_else(|| p.get("name")).cloned().unwrap_or_default(),
201-
"owner_pubkey": p.get("owner_pubkey").cloned().unwrap_or_default(),
202-
"owner_display_name": p.get("owner_display_name").cloned().unwrap_or_default(),
203-
"owned_by_me": p.get("owned_by_me").cloned().unwrap_or_default(),
204140
}))
205141
.collect();
206142
serde_json::to_string(&compact).unwrap_or_default()
@@ -375,11 +311,9 @@ pub async fn dispatch(
375311
) -> Result<(), CliError> {
376312
use crate::UsersCmd;
377313
match cmd {
378-
UsersCmd::Get {
379-
pubkeys,
380-
name,
381-
owner,
382-
} => cmd_get_users(client, &pubkeys, name.as_deref(), owner.as_deref(), format).await,
314+
UsersCmd::Get { pubkeys, name } => {
315+
cmd_get_users(client, &pubkeys, name.as_deref(), format).await
316+
}
383317
UsersCmd::SetProfile {
384318
name,
385319
avatar,
@@ -402,30 +336,9 @@ pub async fn dispatch(
402336

403337
#[cfg(test)]
404338
mod tests {
405-
use super::{copy_owner_fields, presence_subject};
339+
use super::presence_subject;
406340
use serde_json::json;
407341

408-
#[test]
409-
fn copy_owner_fields_marks_authenticated_owner() {
410-
let owner = "a".repeat(64);
411-
let event = json!({
412-
"agent_owner_pubkey": owner,
413-
"agent_owner_display_name": "John",
414-
});
415-
let mut profile = serde_json::Map::new();
416-
copy_owner_fields(&event, &mut profile, &"a".repeat(64));
417-
assert_eq!(profile["owner_display_name"], "John");
418-
assert_eq!(profile["owned_by_me"], true);
419-
}
420-
421-
#[test]
422-
fn copy_owner_fields_marks_other_owner() {
423-
let event = json!({"agent_owner_pubkey": "a".repeat(64)});
424-
let mut profile = serde_json::Map::new();
425-
copy_owner_fields(&event, &mut profile, &"b".repeat(64));
426-
assert_eq!(profile["owned_by_me"], false);
427-
}
428-
429342
#[test]
430343
fn presence_subject_uses_p_tag() {
431344
let event = json!({"pubkey": "relay", "tags": [["p", "user"]]});

‎crates/buzz-cli/src/lib.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,6 @@ pub enum UsersCmd {
808808
/// Search by display name (case-insensitive substring match)
809809
#[arg(long = "name")]
810810
name: Option<String>,
811-
/// Filter agents by verified owner (`me`, 64-char hex, or npub)
812-
#[arg(long = "owner")]
813-
owner: Option<String>,
814811
},
815812
/// Update the current identity's profile
816813
#[command(name = "set-profile")]

‎crates/buzz-db/src/lib.rs‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,24 +1843,6 @@ impl Db {
18431843
user::search_users(&self.pool, community_id, query, limit).await
18441844
}
18451845

1846-
/// Return agent pubkeys whose verified owner matches `owner_pubkey`.
1847-
pub async fn list_agent_pubkeys_by_owner(
1848-
&self,
1849-
community_id: CommunityId,
1850-
owner_pubkey: &[u8],
1851-
) -> Result<Vec<Vec<u8>>> {
1852-
user::list_agent_pubkeys_by_owner(&self.pool, community_id, owner_pubkey).await
1853-
}
1854-
1855-
/// Fetch verified ownership metadata for the requested agent pubkeys.
1856-
pub async fn get_agent_owners(
1857-
&self,
1858-
community_id: CommunityId,
1859-
agent_pubkeys: &[Vec<u8>],
1860-
) -> Result<Vec<user::AgentOwner>> {
1861-
user::get_agent_owners(&self.pool, community_id, agent_pubkeys).await
1862-
}
1863-
18641846
/// Atomically set agent owner — only if no owner is currently assigned.
18651847
/// Returns Ok(true) if set, Ok(false) if an owner already exists.
18661848
pub async fn set_agent_owner(

‎crates/buzz-db/src/migration.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ mod tests {
560560
let mut migrations: Vec<_> = MIGRATOR.iter().collect();
561561
migrations.sort_by_key(|migration| migration.version);
562562

563-
assert_eq!(migrations.len(), 25);
563+
assert_eq!(migrations.len(), 24);
564564
assert_eq!(migrations[0].version, 1);
565565
assert_eq!(&*migrations[0].description, "initial schema");
566566
assert!(migrations[0]

‎crates/buzz-db/src/user.rs‎

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ use buzz_core::CommunityId;
55
use sqlx::PgPool;
66
use sqlx::Row;
77

8-
/// Ownership metadata for an agent profile.
9-
#[derive(Debug, Clone, PartialEq, Eq)]
10-
pub struct AgentOwner {
11-
/// Raw agent public key.
12-
pub agent_pubkey: Vec<u8>,
13-
/// Raw owner public key, verified when the agent authenticated via NIP-OA.
14-
pub owner_pubkey: Vec<u8>,
15-
/// Owner's current display name, when available.
16-
pub owner_display_name: Option<String>,
17-
}
18-
198
/// A user's profile fields.
209
#[derive(Debug, Clone)]
2110
pub struct UserProfile {
@@ -291,65 +280,6 @@ pub async fn search_users(
291280
.collect())
292281
}
293282

294-
/// Return agent pubkeys whose verified owner matches `owner_pubkey`.
295-
pub async fn list_agent_pubkeys_by_owner(
296-
pool: &PgPool,
297-
community_id: CommunityId,
298-
owner_pubkey: &[u8],
299-
) -> Result<Vec<Vec<u8>>> {
300-
let rows = sqlx::query_scalar::<_, Vec<u8>>(
301-
r#"
302-
SELECT pubkey
303-
FROM users
304-
WHERE community_id = $1 AND agent_owner_pubkey = $2
305-
"#,
306-
)
307-
.bind(community_id.as_uuid())
308-
.bind(owner_pubkey)
309-
.fetch_all(pool)
310-
.await?;
311-
Ok(rows)
312-
}
313-
314-
/// Fetch verified ownership metadata for the requested agent pubkeys.
315-
pub async fn get_agent_owners(
316-
pool: &PgPool,
317-
community_id: CommunityId,
318-
agent_pubkeys: &[Vec<u8>],
319-
) -> Result<Vec<AgentOwner>> {
320-
if agent_pubkeys.is_empty() {
321-
return Ok(Vec::new());
322-
}
323-
324-
let rows = sqlx::query_as::<_, (Vec<u8>, Vec<u8>, Option<String>)>(
325-
r#"
326-
SELECT agent.pubkey, agent.agent_owner_pubkey, owner.display_name
327-
FROM users agent
328-
LEFT JOIN users owner
329-
ON owner.community_id = agent.community_id
330-
AND owner.pubkey = agent.agent_owner_pubkey
331-
WHERE agent.community_id = $1
332-
AND agent.pubkey = ANY($2)
333-
AND agent.agent_owner_pubkey IS NOT NULL
334-
"#,
335-
)
336-
.bind(community_id.as_uuid())
337-
.bind(agent_pubkeys)
338-
.fetch_all(pool)
339-
.await?;
340-
341-
Ok(rows
342-
.into_iter()
343-
.map(
344-
|(agent_pubkey, owner_pubkey, owner_display_name)| AgentOwner {
345-
agent_pubkey,
346-
owner_pubkey,
347-
owner_display_name,
348-
},
349-
)
350-
.collect())
351-
}
352-
353283
/// Set the owner pubkey for an agent user.
354284
/// The owner pubkey must already exist in the users table (FK constraint).
355285
/// Returns an error if the agent pubkey is not found (rows_affected == 0).
@@ -534,57 +464,6 @@ mod tests {
534464
);
535465
}
536466

537-
#[tokio::test]
538-
#[ignore = "requires Postgres"]
539-
async fn test_agent_owner_queries_are_scoped_and_include_display_name() {
540-
let db = setup_db().await;
541-
let community = make_community(&db.pool).await;
542-
let agent_pk = random_pubkey();
543-
let other_agent_pk = random_pubkey();
544-
let owner_pk = random_pubkey();
545-
let other_owner_pk = random_pubkey();
546-
for pubkey in [&agent_pk, &other_agent_pk, &owner_pk, &other_owner_pk] {
547-
ensure_user(&db.pool, community, pubkey).await.unwrap();
548-
}
549-
update_user_profile(
550-
&db.pool,
551-
community,
552-
&owner_pk,
553-
Some("Owner Name"),
554-
None,
555-
None,
556-
None,
557-
)
558-
.await
559-
.unwrap();
560-
set_agent_owner(&db.pool, community, &agent_pk, &owner_pk)
561-
.await
562-
.unwrap();
563-
set_agent_owner(&db.pool, community, &other_agent_pk, &other_owner_pk)
564-
.await
565-
.unwrap();
566-
567-
assert_eq!(
568-
list_agent_pubkeys_by_owner(&db.pool, community, &owner_pk)
569-
.await
570-
.unwrap(),
571-
vec![agent_pk.clone()]
572-
);
573-
assert_eq!(
574-
get_agent_owners(&db.pool, community, &[agent_pk.clone(), other_agent_pk],)
575-
.await
576-
.unwrap()
577-
.into_iter()
578-
.find(|owner| owner.agent_pubkey == agent_pk)
579-
.unwrap(),
580-
AgentOwner {
581-
agent_pubkey: agent_pk,
582-
owner_pubkey: owner_pk,
583-
owner_display_name: Some("Owner Name".into()),
584-
}
585-
);
586-
}
587-
588467
/// set_channel_add_policy should persist each of the three valid policies.
589468
#[tokio::test]
590469
#[ignore = "requires Postgres"]

0 commit comments

Comments
 (0)