Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Desktop: Updated Entangled node use #1095

Merged
merged 3 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/desktop/native/Entangled.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { fork } from 'child_process';
import path from 'path';
import { powFunc, genFunc } from 'entangled-node';
import { tritsToChars } from 'libs/iota/converter';
import { powTrytesFunc, powBundleFunc, genAddressTritsFunc } from 'entangled-node';

let timeout = null;

Expand Down Expand Up @@ -37,13 +36,22 @@ process.on('message', async (data) => {
const payload = JSON.parse(data);

if (payload.job === 'pow') {
const pow = await powFunc(payload.trytes, payload.mwm);
const pow = await powTrytesFunc(payload.trytes, payload.mwm);
process.send(pow);
}

if (payload.job === 'batchedPow') {
const pow = await powBundleFunc(
payload.trytes,
payload.trunkTransaction,
payload.branchTransaction,
payload.mwm,
);
process.send(pow);
}

if (payload.job === 'gen') {
const seedString = tritsToChars(payload.seed);
const address = await genFunc(seedString, payload.index, payload.security);
const address = await genAddressTritsFunc(payload.seed, payload.index, payload.security);
process.send(address);
}
});
Expand All @@ -52,6 +60,9 @@ const Entangled = {
powFn: async (trytes, mwm) => {
return await exec(JSON.stringify({ job: 'pow', trytes, mwm }));
},
batchedPowFn: async (trytes, trunkTransaction, branchTransaction, mwm) => {
return await exec(JSON.stringify({ job: 'batchedPow', trytes, trunkTransaction, branchTransaction, mwm }));
},
genFn: async (seed, index, security) => {
return await exec(JSON.stringify({ job: 'gen', seed, index, security }));
},
Expand Down
9 changes: 4 additions & 5 deletions src/desktop/native/preload/Electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ const Electron = {

/**
* Do Proof of Work
* @param {string} trytes - Input trytes
* @param {number} mwm - Min Weight Magnitude
* @returns {string} Proof of Work
* @param {boolean} batchedPow - Should return batched PoW function
* @returns {function} Proof of Work
*/
powFn: async (trytes, mwm) => {
return await Entangled.powFn(trytes, mwm);
getPowFn: (batchedPow) => {
return batchedPow ? Entangled.batchedPowFn : Entangled.powFn;
},

/**
Expand Down
5 changes: 4 additions & 1 deletion src/desktop/src/libs/SeedStore/Keychain.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ACC_MAIN, sha256, encrypt, decrypt } from 'libs/crypto';
import { ALIAS_REALM } from 'libs/realm';
import { byteToTrit } from 'libs/iota/converter';
import { prepareTransfersAsync } from 'libs/iota/extendedApi';
import { tritsToChars } from 'libs/iota/converter';

import SeedStoreCore from './SeedStoreCore';

Expand Down Expand Up @@ -161,7 +162,9 @@ class Keychain extends SeedStoreCore {

Electron.garbageCollect();

return addresses;
return !options.total || options.total === 1
? tritsToChars(addresses)
: addresses.map((trits) => tritsToChars(trits));
};

/**
Expand Down
13 changes: 4 additions & 9 deletions src/desktop/src/libs/SeedStore/SeedStoreCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ export default class SeedStoreCore {
* @param {string} trunkTransaction
* @param {string} branchTransaction
* @param {number} minWeightMagnitude
* @param {boolean} batchedPow
*
* @returns {Promise<object>}
*/
performPow(trytes, trunkTransaction, branchTransaction, minWeightMagnitude) {
return performPow(
Electron.powFn,
this.getDigest,
trytes,
trunkTransaction,
branchTransaction,
minWeightMagnitude,
);
performPow(trytes, trunkTransaction, branchTransaction, minWeightMagnitude, batchedPow) {
const powFn = Electron.getPowFn(batchedPow);
return performPow(powFn, this.getDigest, trytes, trunkTransaction, branchTransaction, minWeightMagnitude);
}

/**
Expand Down