Compare commits

...

2 Commits

View File

@ -699,12 +699,11 @@ export class Service {
const data: Record<string, any> = {};
// Now we decrypt all we can in the processes
for (const [processId, process] of Object.entries(filteredProcesses)) {
console.log('process roles:', this.getRoles(process));
// We also take the public data
const lastState = this.getLastCommitedState(process);
let lastState = this.getLastCommitedState(process);
if (!lastState) {
console.error(`❌ Process ${processId} doesn't have a commited state`);
continue;
// fallback on the first state
lastState = process.states[0];
}
const processData: Record<string, any> = {};
for (const attribute of Object.keys(lastState.public_data)) {
@ -1295,7 +1294,7 @@ export class Service {
if (clear) {
// deserialize the result to get the actual data
const decoded = wasm.decode_value(clear);
return decoded;
return this.convertMapsToObjects(decoded);
} else {
throw new Error('decrypt_data returned null');
}
@ -1310,13 +1309,49 @@ export class Service {
decodeValue(value: number[]): any | null {
try {
return wasm.decode_value(new Uint8Array(value));
const decoded = wasm.decode_value(new Uint8Array(value));
return this.convertMapsToObjects(decoded);
} catch (e) {
console.error(`Failed to decode value: ${e}`);
return null;
}
}
/**
* Convertit récursivement les Map en objets sérialisables
*/
private convertMapsToObjects(obj: any): any {
if (obj === null || obj === undefined) {
return obj;
}
if (obj instanceof Map) {
const result: any = {};
for (const [key, value] of obj.entries()) {
result[key] = this.convertMapsToObjects(value);
}
return result;
}
if (obj instanceof Set) {
return Array.from(obj).map(item => this.convertMapsToObjects(item));
}
if (Array.isArray(obj)) {
return obj.map(item => this.convertMapsToObjects(item));
}
if (typeof obj === 'object') {
const result: any = {};
for (const [key, value] of Object.entries(obj)) {
result[key] = this.convertMapsToObjects(value);
}
return result;
}
return obj;
}
public async updateDevice(): Promise<void> {
let myPairingProcessId: string;
try {