Add some decoding logic in service
This commit is contained in:
parent
8eb6f36b64
commit
8260c6c5da
@ -1001,8 +1001,17 @@ export default class Services {
|
||||
console.error('Unknown process');
|
||||
return;
|
||||
}
|
||||
const spAddressList = process.states[0].public_data['pairedAddresses'];
|
||||
console.log(spAddressList);
|
||||
|
||||
let spAddressList: string[] = [];
|
||||
try {
|
||||
const encodedSpAddressList = process.states[0].public_data['pairedAddresses'];
|
||||
spAddressList = this.sdkClient.decode_value(encodedSpAddressList);
|
||||
if (!spAddressList || spAddressList.length == 0) {
|
||||
throw new Error('Empty pairedAddresses');
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to get pairedAddresses from process: ${e}`);
|
||||
}
|
||||
try {
|
||||
this.sdkClient.pair_device(this.processId, spAddressList);
|
||||
} catch (e) {
|
||||
@ -1301,7 +1310,7 @@ export default class Services {
|
||||
const processes: Record<string, Process> = await db.dumpStore('processes');
|
||||
if (processes && Object.keys(processes).length != 0) {
|
||||
console.log(`Restoring ${Object.keys(processes).length} processes`);
|
||||
this.sdkClient.set_process_cache(JSON.stringify(processes));
|
||||
this.sdkClient.set_process_cache(processes);
|
||||
} else {
|
||||
console.log('No processes to restore!');
|
||||
}
|
||||
@ -1358,7 +1367,7 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
|
||||
async decryptAttribute(processId: string, state: ProcessState, attribute: string): Promise<string | null> {
|
||||
async decryptAttribute(processId: string, state: ProcessState, attribute: string): Promise<any | null> {
|
||||
let hash = state.pcd_commitment[attribute];
|
||||
if (!hash) {
|
||||
// attribute doesn't exist
|
||||
@ -1392,10 +1401,18 @@ export default class Services {
|
||||
const keyBlob = this.hexToBlob(key);
|
||||
const keyBuf = await keyBlob.arrayBuffer();
|
||||
|
||||
const clear = this.sdkClient.decrypt_data(new Uint8Array(keyBuf), cipher);
|
||||
if (clear) {
|
||||
// Parse the stringified JSON
|
||||
return JSON.parse(clear);
|
||||
try {
|
||||
const clear = this.sdkClient.decrypt_data(new Uint8Array(keyBuf), cipher);
|
||||
if (clear) {
|
||||
// deserialize the result to get the actual data
|
||||
const decoded = this.sdkClient.decode_value(clear);
|
||||
console.log('Decoded value:', JSON.stringify(decoded));
|
||||
return decoded;
|
||||
} else {
|
||||
throw new Error('decrypt_data returned null');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to decrypt data:', e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user