feat: import matching business nsec into native identity storage
This commit is contained in:
@@ -159,6 +159,8 @@ impl RpcHandler {
|
||||
|
||||
// Multi-identity management
|
||||
"identity.list" => self.handle_identity_list(params).await,
|
||||
"identity.capabilities" => Ok(serde_json::json!({"import_nostr":true})),
|
||||
"identity.import-nostr" => self.handle_identity_import_nostr(params).await,
|
||||
"identity.create" => self.handle_identity_create(params).await,
|
||||
"identity.get" => self.handle_identity_get(params).await,
|
||||
"identity.delete" => self.handle_identity_delete(params).await,
|
||||
|
||||
@@ -112,6 +112,25 @@ impl RpcHandler {
|
||||
}))
|
||||
}
|
||||
|
||||
/// Explicit owner-key import into a separate native business identity.
|
||||
pub(in crate::api::rpc) async fn handle_identity_import_nostr(
|
||||
&self, params: Option<serde_json::Value>,
|
||||
) -> Result<serde_json::Value> {
|
||||
let params = params.unwrap_or_default();
|
||||
let password = params.get("password").and_then(|v| v.as_str()).unwrap_or("");
|
||||
if !self.auth_manager.verify_password(password).await? {
|
||||
anyhow::bail!("Invalid node password");
|
||||
}
|
||||
let name = params.get("name").and_then(|v| v.as_str()).unwrap_or("Just Works");
|
||||
anyhow::ensure!(!name.trim().is_empty() && name.len() <= 100, "Invalid identity name");
|
||||
let nsec = params.get("nsec").and_then(|v| v.as_str()).unwrap_or("").trim();
|
||||
let npub = params.get("expected_npub").and_then(|v| v.as_str()).unwrap_or("");
|
||||
let manager = IdentityManager::new(&self.config.data_dir).await?;
|
||||
let record = manager.import_nostr(name.to_string(), nsec, npub).await?;
|
||||
Ok(serde_json::json!({"id":record.id, "name":record.name,
|
||||
"nostr_npub":record.nostr_npub, "nostr_pubkey":record.nostr_pubkey}))
|
||||
}
|
||||
|
||||
/// Get a single identity by ID.
|
||||
pub(in crate::api::rpc) async fn handle_identity_get(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user