[bug] Do not request keys when we are not in the role in decryptAttribute

This commit is contained in:
Sosthene 2025-06-15 22:12:22 +02:00 committed by NicolasCantu
parent bb5d3ff16d
commit 6076c342f8

View File

@ -1049,9 +1049,26 @@ export default class Services {
return null;
}
let key = state.keys[attribute];
const pairingProcessId = this.getPairingProcessId();
// If key is missing, request an update and then retry
if (!key) {
const roles = state.roles;
let hasAccess = false;
// If we're not supposed to have access to this attribute, ignore
for (const role of Object.values(roles)) {
if (role.validation_rules.includes(attribute)) {
if (role.members.includes(pairingProcessId)) {
// We have access to this attribute
hasAccess = true;
break;
}
}
}
if (!hasAccess) return null;
// We should have the key, so we're going to ask other members for it
await this.requestDataFromPeers(processId, [state.state_id], [state.roles]);
const maxRetries = 5;
@ -1292,7 +1309,6 @@ export default class Services {
}, 1000)
}
public getRoles(process: Process): Record<string, RoleDefinition> | null {
const lastCommitedState = this.getLastCommitedState(process);
if (lastCommitedState && lastCommitedState.roles && Object.keys(lastCommitedState.roles).length != 0) {
@ -1358,7 +1374,6 @@ export default class Services {
public async requestDataFromPeers(processId: string, stateIds: string[], roles: Record<string, RoleDefinition>[]) {
console.log('Requesting data from peers');
console.log(roles);
const membersList = this.getAllMembers();
try {
const res = this.sdkClient.request_data(processId, stateIds, roles, membersList);