Skip to content

Commit 6c2f80e

Browse files
committed
Hotfix
1 parent b16d144 commit 6c2f80e

File tree

10 files changed

+102
-25
lines changed

10 files changed

+102
-25
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.5.0-1 (Hotfix)
2+
3+
* Fix validation for deleting the last signatory of a company
4+
* Fix plain text identity chain bug when accepting/rejecting an invite
5+
* Fix company logo and file upload to use company key instead of personal key
6+
* Fix switching to personal identity when deleting oneself from company
7+
18
# 0.5.0
29

310
* Stabilise Identity Proof Implementation

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace.package]
2-
version = "0.5.0"
2+
version = "0.5.0-1"
33
edition = "2024"
44
license = "MIT"
55

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use bcr_ebill_core::application::company::{
1212
Company, CompanySignatory, CompanySignatoryStatus, CompanyStatus, LocalSignatoryOverrideStatus,
1313
};
1414
use bcr_ebill_core::application::contact::Contact;
15+
use bcr_ebill_core::application::identity::ActiveIdentityState;
1516
use bcr_ebill_core::application::{ServiceTraitBounds, ValidationError};
1617
use bcr_ebill_core::protocol::Identification;
1718
use bcr_ebill_core::protocol::Name;
@@ -593,7 +594,7 @@ impl CompanyServiceApi for CompanyService {
593594
.process_upload_file(
594595
&proof_of_registration_file_upload_id,
595596
&id,
596-
&full_identity.key_pair.pub_key(),
597+
&company_keys.pub_key(),
597598
nostr_relay,
598599
UploadFileType::Document,
599600
)
@@ -603,7 +604,7 @@ impl CompanyServiceApi for CompanyService {
603604
.process_upload_file(
604605
&logo_file_upload_id,
605606
&id,
606-
&full_identity.key_pair.pub_key(),
607+
&company_keys.pub_key(),
607608
nostr_relay,
608609
UploadFileType::Picture,
609610
)
@@ -859,7 +860,7 @@ impl CompanyServiceApi for CompanyService {
859860
self.process_upload_file(
860861
&logo_file_upload_id,
861862
id,
862-
&full_identity.key_pair.pub_key(),
863+
&company_keys.pub_key(),
863864
nostr_relay,
864865
UploadFileType::Picture,
865866
)
@@ -876,7 +877,7 @@ impl CompanyServiceApi for CompanyService {
876877
self.process_upload_file(
877878
&proof_of_registration_file_upload_id,
878879
id,
879-
&full_identity.key_pair.pub_key(),
880+
&company_keys.pub_key(),
880881
nostr_relay,
881882
UploadFileType::Document,
882883
)
@@ -1106,7 +1107,19 @@ impl CompanyServiceApi for CompanyService {
11061107
));
11071108
}
11081109
let company_keys = self.store.get_key_pair(id).await?;
1109-
if company.signatories.len() == 1 {
1110+
// Only count fully accepted signatories
1111+
if company
1112+
.signatories
1113+
.iter()
1114+
.filter(|s| {
1115+
matches!(
1116+
s.status,
1117+
CompanySignatoryStatus::InviteAcceptedIdentityProven { .. }
1118+
)
1119+
})
1120+
.count()
1121+
== 1
1122+
{
11101123
return Err(super::Error::Validation(
11111124
ProtocolValidationError::CantRemoveLastSignatory.into(),
11121125
));
@@ -1186,6 +1199,25 @@ impl CompanyServiceApi for CompanyService {
11861199
if let Err(e) = self.company_blockchain_store.remove(id).await {
11871200
error!("Could not delete local company chain for {id}: {e}");
11881201
}
1202+
// If the current active identity is the company we're removed from - set to personal identity
1203+
if let Ok(Some(active_node_id)) = self
1204+
.identity_store
1205+
.get_current_identity()
1206+
.await
1207+
.map(|i| i.company)
1208+
&& &active_node_id == id
1209+
&& let Err(e) = self
1210+
.identity_store
1211+
.set_current_identity(&ActiveIdentityState {
1212+
personal: full_identity.identity.node_id,
1213+
company: None,
1214+
})
1215+
.await
1216+
{
1217+
error!(
1218+
"Couldn't set active identity to personal after removing self from company: {e}"
1219+
);
1220+
}
11891221
}
11901222
debug!(
11911223
"removed signatory {} to company with id: {id}",
@@ -3287,6 +3319,12 @@ pub mod tests {
32873319
key_pair: keys_clone_clone.clone(),
32883320
})
32893321
});
3322+
identity_store.expect_get_current_identity().returning(|| {
3323+
Ok(ActiveIdentityState {
3324+
personal: node_id_test(),
3325+
company: None,
3326+
})
3327+
});
32903328
storage.expect_update().returning(|_, _| Ok(()));
32913329
storage.expect_remove().returning(|_| Ok(()));
32923330
identity_chain_store

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub mod restore;
1212
mod transport;
1313
pub mod transport_client;
1414

15-
use log::error;
1615
use serde::{Deserialize, Serialize};
1716
use thiserror::Error;
1817

crates/bcr-ebill-core/src/protocol/blockchain/identity/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ impl IdentityBlockPlaintextWrapper {
9191
IdentityOpCode::InviteSignatory => {
9292
borsh_to_json_value::<IdentityInviteSignatoryBlockData>(&self.plaintext_data_bytes)?
9393
}
94-
IdentityOpCode::AcceptSignatoryInvite => {
95-
borsh_to_json_value::<IdentityInviteSignatoryBlockData>(&self.plaintext_data_bytes)?
96-
}
97-
IdentityOpCode::RejectSignatoryInvite => {
98-
borsh_to_json_value::<IdentityInviteSignatoryBlockData>(&self.plaintext_data_bytes)?
99-
}
94+
IdentityOpCode::AcceptSignatoryInvite => borsh_to_json_value::<
95+
IdentityAcceptSignatoryInviteBlockData,
96+
>(&self.plaintext_data_bytes)?,
97+
IdentityOpCode::RejectSignatoryInvite => borsh_to_json_value::<
98+
IdentityRejectSignatoryInviteBlockData,
99+
>(&self.plaintext_data_bytes)?,
100100
IdentityOpCode::RemoveSignatory => {
101101
borsh_to_json_value::<IdentityRemoveSignatoryBlockData>(&self.plaintext_data_bytes)?
102102
}

crates/bcr-ebill-core/src/protocol/blockchain/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ pub trait Blockchain {
268268
) -> Option<&Self::Block> {
269269
self.blocks()
270270
.iter()
271-
.filter(|block| block.op_code() == &op_code)
272-
.next_back()
271+
.rfind(|block| block.op_code() == &op_code)
273272
}
274273

275274
/// Checks if there is any block with a given operation code in the current blocks list.

crates/bcr-ebill-transport/src/handler/company_chain_event_processor.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bcr_ebill_api::service::transport_service::transport_client::TransportClient
1111
use bcr_ebill_core::{
1212
application::{
1313
company::CompanyStatus,
14+
identity::ActiveIdentityState,
1415
notification::{Notification, NotificationType},
1516
},
1617
protocol::{
@@ -410,13 +411,39 @@ impl CompanyChainEventProcessor {
410411
.await
411412
.map_err(|e| Error::Persistence(e.to_string()))?;
412413
}
413-
update @ CompanyBlockPayload::RemoveSignatory(_) => {
414+
CompanyBlockPayload::RemoveSignatory(payload) => {
415+
let removee = payload.removee.clone();
414416
info!("Removing signatory from company {company_id}");
415-
company.apply_block_data(&update, identity_node_id, block.timestamp());
417+
company.apply_block_data(
418+
&CompanyBlockPayload::RemoveSignatory(payload),
419+
identity_node_id,
420+
block.timestamp(),
421+
);
416422
self.company_store
417423
.update(company_id, company)
418424
.await
419425
.map_err(|e| Error::Persistence(e.to_string()))?;
426+
427+
// if we're being removed and current identity is that company - change it
428+
if &removee == identity_node_id
429+
&& let Ok(Some(active_node_id)) = self
430+
.identity_store
431+
.get_current_identity()
432+
.await
433+
.map(|i| i.company)
434+
&& &active_node_id == company_id
435+
&& let Err(e) = self
436+
.identity_store
437+
.set_current_identity(&ActiveIdentityState {
438+
personal: identity_node_id.to_owned(),
439+
company: None,
440+
})
441+
.await
442+
{
443+
error!(
444+
"Couldn't set active identity to personal after removing self from company: {e}"
445+
);
446+
}
420447
}
421448
CompanyBlockPayload::SignBill(payload) => {
422449
if let Some(bill_key) = payload.bill_key

crates/bcr-ebill-wasm/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ <h2>Company Testing</h2>
103103
<button type="button" id="company_list">List Companies</button>
104104
<button type="button" id="list_signatories">List Signatories</button>
105105
<button type="button" id="sync_company_chain">Sync Company Chain</button>
106+
<button type="button" id="get_proof_file">Get Proof Of Registration File</button>
106107
<h3>Company Identity Proof</h3>
107108
Company Signatory Email: <input type="text" id="company_email"/>
108109
<button type="button" id="confirm_company_email">Confirm Company Signatory Email</button>

crates/bcr-ebill-wasm/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ document.getElementById("get_company_invites").addEventListener("click", getComp
9494
document.getElementById("company_accept_invite").addEventListener("click", acceptCompanyInvite);
9595
document.getElementById("company_reject_invite").addEventListener("click", rejectCompanyInvite);
9696
document.getElementById("locally_hide_signatory").addEventListener("click", locallyHideRemovedSignatory);
97+
document.getElementById("get_proof_file").addEventListener("click", fetchCompanyFile);
9798

9899
// restore account, backup seed phrase
99100
document.getElementById("get_seed_phrase").addEventListener("click", getSeedPhrase);
@@ -274,6 +275,7 @@ async function createCompany() {
274275
address: "street 1",
275276
},
276277
creator_email: company_email,
278+
proof_of_registration_file_upload_id: document.getElementById("file_upload_id").value || undefined,
277279
}));
278280
console.log("company: ", company);
279281
}
@@ -742,6 +744,15 @@ async function syncCompanyChain() {
742744
await measured();
743745
}
744746

747+
async function fetchCompanyFile() {
748+
let node_id = document.getElementById("company_id").value;
749+
let detail = success_or_fail(await window.companyApi.detail(node_id));
750+
let file_name = detail.proof_of_registration_file.name;
751+
let file = success_or_fail(await window.companyApi.file_base64(node_id, file_name));
752+
753+
document.getElementById("bill_attached_file").src = `data:${file.content_type};base64,${file.data}`;
754+
}
755+
745756
async function companyDetail() {
746757
let node_id = document.getElementById("company_id").value;
747758
console.log("companyDetail", node_id);

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,11 @@ use crate::{
3838

3939
async fn get_file(id: &str, file_name: &Name) -> Result<(Vec<u8>, String)> {
4040
let parsed_id = NodeId::from_str(id).map_err(ProtocolValidationError::from)?;
41-
let company = get_ctx()
41+
let (company, keys) = get_ctx()
4242
.company_service
43-
.get_company_by_id(&parsed_id)
43+
.get_company_and_keys_by_id(&parsed_id)
4444
.await?; // check if company exists
45-
let private_key = get_ctx()
46-
.identity_service
47-
.get_full_identity()
48-
.await?
49-
.key_pair
50-
.get_private_key();
45+
let private_key = keys.get_private_key();
5146

5247
let file_bytes = get_ctx()
5348
.company_service

0 commit comments

Comments
 (0)