decryptAttribute request missing data
This commit is contained in:
parent
3d09a20512
commit
3785285e4d
@ -917,21 +917,27 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async decryptAttribute(state: ProcessState, attribute: string): Promise<string | null> {
|
async decryptAttribute(processId: string, state: ProcessState, attribute: string): Promise<string | null> {
|
||||||
let hash;
|
let hash = state.pcd_commitment[attribute];
|
||||||
let key;
|
let key = state.keys[attribute];
|
||||||
try {
|
|
||||||
hash = state.pcd_commitment[attribute];
|
// If hash or key is missing, request an update and then retry
|
||||||
} catch (e) {
|
if (!hash || !key) {
|
||||||
console.error(`Failed to find hash for attribute ${attribute}`);
|
await this.requestDataFromPeers(processId, [state.state_id], [state.roles]);
|
||||||
return null;
|
|
||||||
}
|
const maxRetries = 5;
|
||||||
try {
|
const retryDelay = 500; // delay in milliseconds
|
||||||
key = state.keys[attribute];
|
let retries = 0;
|
||||||
} catch (e) {
|
|
||||||
console.error(`Failed to find key for attribute ${attribute}`);
|
while ((!hash || !key) && retries < maxRetries) {
|
||||||
return null;
|
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
||||||
|
// Re-read hash and key after waiting
|
||||||
|
hash = state.pcd_commitment[attribute];
|
||||||
|
key = state.keys[attribute];
|
||||||
|
retries++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hash && key) {
|
if (hash && key) {
|
||||||
const blob = await this.getBlobFromDb(hash);
|
const blob = await this.getBlobFromDb(hash);
|
||||||
if (blob) {
|
if (blob) {
|
||||||
@ -943,7 +949,7 @@ export default class Services {
|
|||||||
|
|
||||||
const clear = this.sdkClient.decrypt_data(new Uint8Array(keyBuf), cipher);
|
const clear = this.sdkClient.decrypt_data(new Uint8Array(keyBuf), cipher);
|
||||||
if (clear) {
|
if (clear) {
|
||||||
// This is stringified json, we parse it back
|
// Parse the stringified JSON
|
||||||
return JSON.parse(clear);
|
return JSON.parse(clear);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user