Compare commits

...

3 Commits

Author SHA1 Message Date
Sosthene
19da967605 Remove unnecessary async 2025-08-25 01:32:24 +02:00
Sosthene
d4223ce604 [bug] Correct args for parse_cipher 2025-08-25 01:31:35 +02:00
Sosthene
420979e63e [bug] Prevent duplicated addresses when sharing secrets 2025-08-25 01:30:58 +02:00

View File

@ -211,7 +211,7 @@ export default class Services {
public async checkConnections(members: Member[]): Promise<void> { public async checkConnections(members: Member[]): Promise<void> {
// Ensure the amount is available before proceeding // Ensure the amount is available before proceeding
await this.getTokensFromFaucet(); await this.getTokensFromFaucet();
let unconnectedAddresses = []; let unconnectedAddresses: Set<string> = new Set();
const myAddress = this.getDeviceAddress(); const myAddress = this.getDeviceAddress();
for (const member of members) { for (const member of members) {
const sp_addresses = member.sp_addresses; const sp_addresses = member.sp_addresses;
@ -221,12 +221,12 @@ export default class Services {
if (address === myAddress) continue; if (address === myAddress) continue;
const sharedSecret = await this.getSecretForAddress(address); const sharedSecret = await this.getSecretForAddress(address);
if (!sharedSecret) { if (!sharedSecret) {
unconnectedAddresses.push(address); unconnectedAddresses.add(address);
} }
} }
} }
if (unconnectedAddresses && unconnectedAddresses.length != 0) { if (unconnectedAddresses && unconnectedAddresses.size != 0) {
const apiResult = await this.connectAddresses(unconnectedAddresses); const apiResult = await this.connectAddresses([...unconnectedAddresses]);
await this.handleApiReturn(apiResult); await this.handleApiReturn(apiResult);
} }
} }
@ -504,15 +504,15 @@ export default class Services {
await db.clearStore('diffs'); await db.clearStore('diffs');
} }
async sendNewTxMessage(message: string) { sendNewTxMessage(message: string) {
sendMessage('NewTx', message); sendMessage('NewTx', message);
} }
async sendCommitMessage(message: string) { sendCommitMessage(message: string) {
sendMessage('Commit', message); sendMessage('Commit', message);
} }
async sendCipherMessages(ciphers: string[]) { sendCipherMessages(ciphers: string[]) {
for (let i = 0; i < ciphers.length; i++) { for (let i = 0; i < ciphers.length; i++) {
const cipher = ciphers[i]; const cipher = ciphers[i];
sendMessage('Cipher', cipher); sendMessage('Cipher', cipher);
@ -525,9 +525,10 @@ export default class Services {
async parseCipher(message: string) { async parseCipher(message: string) {
const membersList = this.getAllMembers(); const membersList = this.getAllMembers();
const processes = await this.getProcesses();
try { try {
// console.log('parsing new cipher'); // console.log('parsing new cipher');
const apiReturn = this.sdkClient.parse_cipher(message, membersList); const apiReturn = this.sdkClient.parse_cipher(message, membersList, processes);
await this.handleApiReturn(apiReturn); await this.handleApiReturn(apiReturn);
// Device 1 wait Device 2 // Device 1 wait Device 2
@ -602,7 +603,7 @@ export default class Services {
} }
if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) { if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) {
await this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send)); this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send));
await new Promise(r => setTimeout(r, 500)); await new Promise(r => setTimeout(r, 500));
} }
@ -676,11 +677,11 @@ export default class Services {
if (apiReturn.commit_to_send) { if (apiReturn.commit_to_send) {
const commit = apiReturn.commit_to_send; const commit = apiReturn.commit_to_send;
await this.sendCommitMessage(JSON.stringify(commit)); this.sendCommitMessage(JSON.stringify(commit));
} }
if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length != 0) { if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length != 0) {
await this.sendCipherMessages(apiReturn.ciphers_to_send); this.sendCipherMessages(apiReturn.ciphers_to_send);
} }
} }
@ -1544,7 +1545,7 @@ export default class Services {
if (dontRetry.includes(errorMsg)) { return; } if (dontRetry.includes(errorMsg)) { return; }
// Wait and retry // Wait and retry
setTimeout(async () => { setTimeout(async () => {
await this.sendCommitMessage(JSON.stringify(content)); this.sendCommitMessage(JSON.stringify(content));
}, 1000) }, 1000)
} }