Skip to content

Commit f064d3c

Browse files
authored
Remove authorized signers (#661)
1 parent 2afffef commit f064d3c

File tree

11 files changed

+87
-51
lines changed

11 files changed

+87
-51
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Added identity and company blocks for identity proofs (breaking DB change)
55
* Add job to regularly check identity proofs
66
* Add `default_court_url` to config and add API to share a bill with a court
7+
* Add API to share company and identity details with an external party
8+
* Removed the concept of an `Authorized Signer`
79

810
# 0.4.8
911

crates/bcr-ebill-api/src/service/bill_service/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ pub mod tests {
672672
assert!(result.is_err());
673673
assert!(matches!(
674674
result.as_ref().unwrap_err(),
675-
Error::Validation(ValidationError::DrawerIsNotBillIssuer)
675+
Error::Validation(ValidationError::SignerCantBeAnon)
676676
));
677677
}
678678

crates/bcr-ebill-api/src/service/identity_service.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,29 +304,32 @@ impl IdentityServiceApi for IdentityService {
304304
changed = true;
305305
}
306306

307-
util::update_optional_field(
308-
&mut identity.postal_address.country,
309-
&postal_address.country,
310-
&mut changed,
311-
);
307+
if let Some(ref country_to_set) = postal_address.country
308+
&& identity.postal_address.country != Some(country_to_set.trim().to_string())
309+
{
310+
identity.postal_address.country = Some(country_to_set.trim().to_owned());
311+
changed = true;
312+
}
312313

313-
util::update_optional_field(
314-
&mut identity.postal_address.city,
315-
&postal_address.city,
316-
&mut changed,
317-
);
314+
if let Some(ref city_to_set) = postal_address.city
315+
&& identity.postal_address.city != Some(city_to_set.trim().to_string())
316+
{
317+
identity.postal_address.city = Some(city_to_set.trim().to_owned());
318+
changed = true;
319+
}
318320

319321
util::update_optional_field(
320322
&mut identity.postal_address.zip,
321323
&postal_address.zip,
322324
&mut changed,
323325
);
324326

325-
util::update_optional_field(
326-
&mut identity.postal_address.address,
327-
&postal_address.address,
328-
&mut changed,
329-
);
327+
if let Some(ref address_to_set) = postal_address.address
328+
&& identity.postal_address.address != Some(address_to_set.trim().to_string())
329+
{
330+
identity.postal_address.address = Some(address_to_set.trim().to_owned());
331+
changed = true;
332+
}
330333

331334
util::update_optional_field(&mut identity.date_of_birth, &date_of_birth, &mut changed);
332335

@@ -755,7 +758,7 @@ mod tests {
755758
service::notification_service::MockNotificationServiceApi,
756759
tests::tests::{
757760
MockFileUploadStoreApiMock, MockIdentityChainStoreApiMock, MockIdentityStoreApiMock,
758-
empty_identity, empty_optional_address, init_test_cfg,
761+
empty_identity, empty_optional_address, filled_optional_address, init_test_cfg,
759762
},
760763
};
761764
use mockall::predicate::eq;
@@ -814,7 +817,7 @@ mod tests {
814817
IdentityType::Ident,
815818
"name".to_string(),
816819
Some("email".to_string()),
817-
empty_optional_address(),
820+
filled_optional_address(),
818821
None,
819822
None,
820823
None,
@@ -918,7 +921,7 @@ mod tests {
918921
IdentityType::Ident,
919922
"name".to_string(),
920923
Some("email".to_string()),
921-
empty_optional_address(),
924+
filled_optional_address(),
922925
None,
923926
None,
924927
None,

crates/bcr-ebill-api/src/tests/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,15 @@ pub mod tests {
506506
}
507507
}
508508

509+
pub fn filled_optional_address() -> OptionalPostalAddress {
510+
OptionalPostalAddress {
511+
country: Some("AT".to_string()),
512+
city: Some("Vienna".to_string()),
513+
zip: None,
514+
address: Some("Some Address 1".to_string()),
515+
}
516+
}
517+
509518
pub fn empty_optional_address() -> OptionalPostalAddress {
510519
OptionalPostalAddress {
511520
country: None,

crates/bcr-ebill-core/src/bill/validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn validate_bill_issue(data: &BillIssueData) -> Result<(u64, BillType), Vali
2323

2424
// anon users can't issue bill
2525
if let BillParticipant::Anon(_) = data.drawer_public_data {
26-
return Err(ValidationError::DrawerIsNotBillIssuer);
26+
return Err(ValidationError::SignerCantBeAnon);
2727
}
2828

2929
let issue_date_ts = util::date::date_string_to_timestamp(&data.issue_date, None)?;

crates/bcr-ebill-core/src/contact/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl BillIdentParticipant {
307307
email: identity.email,
308308
nostr_relays: identity.nostr_relays,
309309
}),
310-
None => Err(ValidationError::IdentityIsNotBillIssuer),
310+
None => Err(ValidationError::IdentityCantBeAnon),
311311
}
312312
}
313313
}

crates/bcr-ebill-core/src/identity/validation.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ pub fn validate_create_identity(
2727
} else {
2828
return Err(ValidationError::FieldEmpty(Field::Email));
2929
}
30-
postal_address.validate()?;
30+
// For Ident, the postal address needs to be fully set
31+
postal_address.validate_to_be_non_optional()?;
3132
util::validate_file_upload_id(profile_picture_file_upload_id.as_deref())?;
3233
util::validate_file_upload_id(identity_document_file_upload_id.as_deref())?;
3334
}
@@ -70,7 +71,10 @@ pub fn validate_update_identity(
7071
#[cfg(test)]
7172
mod tests {
7273
use super::*;
73-
use crate::{OptionalPostalAddress, ValidationError, identity::IdentityType};
74+
use crate::{
75+
OptionalPostalAddress, ValidationError, identity::IdentityType,
76+
tests::tests::valid_optional_address,
77+
};
7478
use rstest::rstest;
7579

7680
#[test]
@@ -87,15 +91,18 @@ mod tests {
8791
}
8892

8993
#[rstest]
90-
#[case::invalid_name(IdentityType::Anon, "", &None, &OptionalPostalAddress::empty(), &None, &None, ValidationError::FieldEmpty(Field::Name))]
91-
#[case::ident_no_email(IdentityType::Ident, "some name", &None, &OptionalPostalAddress::empty(), &None, &None, ValidationError::FieldEmpty(Field::Email))]
92-
#[case::ident_blank_email(IdentityType::Ident, "some name", &Some("".into()), &OptionalPostalAddress::empty(), &None, &None, ValidationError::FieldEmpty(Field::Email))]
93-
#[case::ident_blank_address(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: None, city: None, zip: None, address: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::Address))]
94-
#[case::ident_blank_city(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: None, address: None, zip: None, city: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::City))]
95-
#[case::ident_blank_country(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { address: None, city: None, zip: None, country: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::Country))]
96-
#[case::ident_blank_zip(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: None, city: None, address: None, zip: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::Zip))]
97-
#[case::ident_blank_profile_pic(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress::empty(), &Some("".into()), &None, ValidationError::InvalidFileUploadId)]
98-
#[case::ident_blank_identity_doc(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress::empty(), &None, &Some("".into()), ValidationError::InvalidFileUploadId)]
94+
#[case::invalid_name(IdentityType::Anon, "", &None, &valid_optional_address(), &None, &None, ValidationError::FieldEmpty(Field::Name))]
95+
#[case::ident_no_email(IdentityType::Ident, "some name", &None, &valid_optional_address(), &None, &None, ValidationError::FieldEmpty(Field::Email))]
96+
#[case::ident_blank_email(IdentityType::Ident, "some name", &Some("".into()), &valid_optional_address(), &None, &None, ValidationError::FieldEmpty(Field::Email))]
97+
#[case::ident_blank_address(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: Some("AT".to_string()), city: Some("Vienna".to_string()), zip: None, address: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::Address))]
98+
#[case::ident_empty_address(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: Some("AT".to_string()), city: Some("Vienna".to_string()), zip: None, address: None }, &None, &None, ValidationError::FieldEmpty(Field::Address))]
99+
#[case::ident_blank_city(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: Some("AT".to_string()), address: Some("addr 1".to_string()), zip: None, city: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::City))]
100+
#[case::ident_empty_city(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: Some("AT".to_string()), address: Some("addr 1".to_string()), zip: None, city: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::City))]
101+
#[case::ident_blank_country(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { address: Some("addr 1".to_string()), city: Some("Vienna".to_string()), zip: None, country: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::Country))]
102+
#[case::ident_empty_country(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { address: Some("addr 1".to_string()), city: Some("Vienna".to_string()), zip: None, country: None }, &None, &None, ValidationError::FieldEmpty(Field::Country))]
103+
#[case::ident_blank_zip(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: Some("AT".to_string()), city: Some("Vienna".to_string()), address: Some("addr 1".to_string()), zip: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::Zip))]
104+
#[case::ident_blank_profile_pic(IdentityType::Ident, "some name", &Some("[email protected]".into()), &valid_optional_address(), &Some("".into()), &None, ValidationError::InvalidFileUploadId)]
105+
#[case::ident_blank_identity_doc(IdentityType::Ident, "some name", &Some("[email protected]".into()), &valid_optional_address(), &None, &Some("".into()), ValidationError::InvalidFileUploadId)]
99106
fn test_validate_create_identity_errors(
100107
#[case] t: IdentityType,
101108
#[case] name: &str,

crates/bcr-ebill-core/src/lib.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,38 @@ impl OptionalPostalAddress {
288288
}
289289
None
290290
}
291+
292+
fn validate_to_be_non_optional(&self) -> Result<(), ValidationError> {
293+
if self.country.is_none() {
294+
return Err(ValidationError::FieldEmpty(Field::Country));
295+
}
296+
297+
if is_blank(&self.country) {
298+
return Err(ValidationError::FieldEmpty(Field::Country));
299+
}
300+
301+
if self.city.is_none() {
302+
return Err(ValidationError::FieldEmpty(Field::City));
303+
}
304+
305+
if is_blank(&self.city) {
306+
return Err(ValidationError::FieldEmpty(Field::City));
307+
}
308+
309+
if is_blank(&self.zip) {
310+
return Err(ValidationError::FieldEmpty(Field::Zip));
311+
}
312+
313+
if self.address.is_none() {
314+
return Err(ValidationError::FieldEmpty(Field::Address));
315+
}
316+
317+
if is_blank(&self.address) {
318+
return Err(ValidationError::FieldEmpty(Field::Address));
319+
}
320+
321+
Ok(())
322+
}
291323
}
292324

293325
#[derive(Debug)]
@@ -560,14 +592,6 @@ pub enum ValidationError {
560592
#[error("Caller must be signatory for company")]
561593
CallerMustBeSignatory,
562594

563-
/// error returned if the drawer is not a bill issuer
564-
#[error("Drawer is not a bill issuer - does not have a postal address set")]
565-
DrawerIsNotBillIssuer,
566-
567-
/// error returned if the identity is not a bill issuer
568-
#[error("Identity is not a bill issuer - does not have a postal address set")]
569-
IdentityIsNotBillIssuer,
570-
571595
/// error returned if the signatory is not in the contacts
572596
#[error("Node Id {0} is not a person in the contacts.")]
573597
SignatoryNotInContacts(String),

crates/bcr-ebill-wasm/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ async function start(create_identity) {
120120
console.log("local identity:", identity);
121121
} catch (err) {
122122
if (create_identity) {
123-
124123
console.log("No local identity found - creating anon identity..");
125124
await identityApi.create({
126125
t: 1,

crates/bcr-ebill-wasm/src/api/bill.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,10 +971,8 @@ pub(super) async fn get_signer_public_data_and_keys() -> Result<(BillParticipant
971971
identity.key_pair,
972972
),
973973
Err(_) => {
974-
// only non-anon bill issuers with a postal address can sign a bill
975-
return Err(
976-
Error::Validation(ValidationError::DrawerIsNotBillIssuer).into()
977-
);
974+
// only non-anon bill issuers can sign a bill
975+
return Err(Error::Validation(ValidationError::SignerCantBeAnon).into());
978976
}
979977
}
980978
}

0 commit comments

Comments
 (0)