Comment out fn (maybe use it in lecoffre stack)

This commit is contained in:
NicolasCantu 2025-05-21 12:08:02 +02:00
parent 0099a8c858
commit f6edadc535

View File

@ -507,46 +507,85 @@ export default class Services {
if (processes === null) { if (processes === null) {
return null; return null;
} }
for (const processId of processes) { // This look for the process that holds all the notaries
try { // private async lookForNotaryProcess(): Promise<string | null> {
const process = await this.getProcess(processId); // const processes = await this.getProcesses();
// for (const processId of Object.keys(processes)) {
// try {
// const process = await this.getProcess(processId);
const roles = this.getRoles(process); // const roles = this.getRoles(process);
if (!roles) { // if (!roles) {
throw new Error('Failed to get roles'); // console.error('Failed to getRoles');
} // return null;
const roleKeys = Object.keys(roles!); // }
// const roleKeys = Object.keys(roles);
if (roleKeys.includes("notary")) { // if (roleKeys.includes("notary")) {
let publicData; // let publicData;
const lastCommitedState = this.getLastCommitedState(process); // const lastCommitedState = this.getLastCommitedState(process);
if (lastCommitedState) { // // If we don't have a commited state, the notary process might be in initialization phase
publicData = lastCommitedState.public_data; // if (lastCommitedState) {
} else { // publicData = lastCommitedState.public_data;
publicData = process.states[0].public_data; // } else {
} // console.log(`Fallback to first, uncommited state`);
// publicData = process.states[0].public_data;
// }
const publicDataKeys = Object.keys(publicData); // const publicDataKeys = Object.keys(publicData);
if (publicDataKeys.includes("idNotTokens")){ // if (publicDataKeys.includes("idNotTokens")){
return processId; // return processId;
} else { // } else {
continue; // continue;
} // }
} else { // } else {
continue; // continue;
} // }
} catch (e) { // } catch (e) {
console.error(e); // console.error(e);
} // }
} // }
return null; // return null;
} // }
// private async checkIfNotary(): Promise<string | null> {
// const processes = await this.getMyProcesses();
// if (!processes) {
// return null;
// }
// for (const processId of processes) {
// try {
// const process = await this.getProcess(processId);
// const lastCommitedState = this.getLastCommitedState(process);
// if (lastCommitedState) {
// const fields = lastCommitedState.pcd_commitment;
// const fieldsKeys = Object.keys(fields);
// const publicData = lastCommitedState.public_data;
// if (fieldsKeys.includes("idNot") || publicData.identityCertified) {
// console.log(`Found idNot in profile ${processId}, member is notary`);
// return processId;
// } else {
// continue;
// }
// } else {
// continue;
// }
// } catch (e) {
// console.error(e);
// }
// }
// return null;
// }
public async updateProcess(process: Process, privateData: Record<string, any>, publicData: Record<string, any>, roles: Record<string, RoleDefinition> | null): Promise<ApiReturn> { public async updateProcess(process: Process, privateData: Record<string, any>, publicData: Record<string, any>, roles: Record<string, RoleDefinition> | null): Promise<ApiReturn> {
// If roles is null, we just take the last commited state roles // If roles is null, we just take the last commited state roles
@ -1559,4 +1598,142 @@ export default class Services {
return await this.updateProcess(process, {}, publicData, null); return await this.updateProcess(process, {}, publicData, null);
} }
// public async getProfilesAttributes(): Promise<Record<string, Record<string, any>>> {
// const processes = await this.getProcesses();
// const profilesAttributes: Record<string, Record<string, any>> = {};
// for (const processId of Object.keys(processes)) {
// try {
// const process = await this.getProcess(processId);
// let lastCommitedState = this.getLastCommitedState(process);
// // If no committed state, use the first state
// if (!lastCommitedState) {
// lastCommitedState = process.states[0];
// }
// // Check if it's a profile process
// const description = await this.decryptAttribute(processId, lastCommitedState, 'description');
// if (!description || description !== "profile") {
// continue;
// }
// // Get all attributes for this profile
// if (lastCommitedState.pcd_commitment) {
// const attributesKeys = Object.keys(lastCommitedState.pcd_commitment);
// const decryptedAttributes: Record<string, any> = {};
// // Decrypt each attribute
// for (const key of attributesKeys) {
// try {
// const attribute = await this.decryptAttribute(processId, lastCommitedState, key);
// if (attribute !== null) {
// decryptedAttributes[key] = attribute;
// }
// } catch (e) {
// console.error(`Failed to decrypt attribute ${key}:`, e);
// }
// }
// // Add public data (like certification status)
// const publicData = this.getPublicData(process);
// if (publicData) {
// for (const [key, value] of Object.entries(publicData)) {
// decryptedAttributes[key] = value;
// }
// }
// // Only add profiles that have attributes
// if (Object.keys(decryptedAttributes).length > 0) {
// profilesAttributes[processId] = decryptedAttributes;
// }
// }
// } catch (e) {
// console.error(`Error processing process ${processId}:`, e);
// }
// }
// return profilesAttributes;
// }
// public async getNotaryAttributes(): Promise<Record<string, Record<string, any>>> {
// const processes = await this.getProcesses();
// const notaryAttributes: Record<string, Record<string, any>> = {};
// for (const [processId, process] of Object.entries(processes)) {
// try {
// const publicData = this.getPublicData(process);
// if (!publicData || !publicData.name || !publicData.lastName) {
// continue;
// }
// const attributes = {
// name: publicData.name,
// lastName: publicData.lastName,
// };
// notaryAttributes[processId] = attributes;
// } catch (e) {
// console.error(`Error processing process ${processId}:`, e);
// }
// }
// return notaryAttributes;
// }
// public async addDevice(processId: string) {
// const process = await this.getProcess(processId);
// const publicData = this.getPublicData(process);
// if (!publicData) {
// console.error('Invalid process: Failed to get public data');
// return;
// }
// const pairedAddresses = publicData.pairedAddresses;
// if (!pairedAddresses) {
// console.error('Not a pairing process, no pairedAddresses');
// return;
// }
// const roles = this.getRoles(process);
// if (!roles) {
// console.error('Invalid process: Failed to get roles');
// return;
// }
// if (!roles.pairing) {
// console.error('Not a pairing process, no pairing role');
// return;
// }
// const deviceAddress = await this.getDeviceAddress();
// this.device1 = true;
// publicData.pairedAddresses.push(deviceAddress);
// let newState = {
// pairedAddresses: publicData.pairedAddresses,
// }
// try {
// console.log("process", process);
// console.log("newState", newState);
// console.log("roles", roles);
// apiReturn = await this.updateProcess(process, newState, publicData, roles);
// } catch (e) {
// throw new Error(e);
// }
// try {
// const updatedProcess = apiReturn.updated_process.current_process;
// const newStateId = updatedProcess.states[0].state_id;
// await this.handleApiReturn(apiReturn);
// const modalService = await ModalService.getInstance();
// await modalService.openPairingConfirmationModal(roles, processId, newStateId);
// await modalService.confirmAddingDevice();
// } catch (e) {
// console.error('Failed to add device:', e);
// }
// }
} }