Skip to content

Commit

Permalink
Merge pull request #373 from FleekHQ/giancarlo/20192
Browse files Browse the repository at this point in the history
Type for recoverKeysByPassphrase and backupKeysByPassphrase
  • Loading branch information
giankotarola authored Nov 30, 2020
2 parents 9953d1d + ccd05e4 commit 01aa4ea
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ REACT_APP_TORUS_TWITTER_CLIENT_ID=
REACT_APP_TORUS_TWITTER_AUTH_DOMAIN=
REACT_APP_TORUS_PROXY_CONTRACT=
REACT_APP_TORUS_PROVIDERS_REDIRECT_URL=
REACT_APP_TORUS_GOOGLE_CLIENT_ID=
REACT_APP_TORUS_GOOGLE_CLIENT_ID=
REACT_APP_TORUS_PASSWORDLESS_VERIFIER=
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build-storybook": "build-storybook -s public"
},
"dependencies": {
"@fleekhq/space-client": "^1.1.5",
"@fleekhq/space-client": "^1.1.7",
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-brands-svg-icons": "^5.13.0",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
Expand Down
2 changes: 2 additions & 0 deletions public/electron/events/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const get = require('lodash/get');
const { ipcMain } = require('electron');

const { getKeyBackupType } = require('../utils');
const { spaceClient, apiClient } = require('../clients');

const EVENT_PREFIX = 'account';
Expand Down Expand Up @@ -139,6 +140,7 @@ const registerAuthEvents = (mainWindow) => {
await spaceClient.backupKeysByPassphrase({
uuid: payload.uuid,
passphrase: payload.torusRes.privateKey,
type: getKeyBackupType({ typeOfLogin: payload.torusRes.userInfo.typeOfLogin }),
});
const apiSessionRes = await spaceClient.getAPISessionTokens();
await apiClient.identity.addEthAddress({
Expand Down
9 changes: 6 additions & 3 deletions public/electron/events/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { ipcMain } = require('electron');
const { getAddressByPublicKey } = require('../utils');

const { apiClient, spaceClient } = require('../clients');
const { getKeyBackupType, getAddressByPublicKey } = require('../utils');

const EVENT_PREFIX = 'auth';
const SIGNIN_EVENT = `${EVENT_PREFIX}:signin`;
Expand Down Expand Up @@ -30,6 +31,7 @@ const registerAuthEvents = (mainWindow) => {
await spaceClient.recoverKeysByPassphrase({
uuid: data.data.uuid,
passphrase: payload.password,
type: getKeyBackupType({ typeOfLogin: 'password' }),
});

user = { ...data.data };
Expand All @@ -42,6 +44,7 @@ const registerAuthEvents = (mainWindow) => {
await spaceClient.recoverKeysByPassphrase({
uuid: data.data.uuid,
passphrase: payload.torusRes.privateKey,
type: getKeyBackupType({ typeOfLogin: payload.torusRes.userInfo.typeOfLogin }),
});

user = { ...data.data };
Expand Down Expand Up @@ -98,9 +101,9 @@ const registerAuthEvents = (mainWindow) => {
token: apiSessionRes.getServicestoken(),
});
await spaceClient.backupKeysByPassphrase({
type: 0, // 0 = PASSWORD; 1 = ETH
uuid: data.data.uuid,
passphrase: payload.password,
type: getKeyBackupType({ typeOfLogin: 'password' }),
});

user = { ...data.data };
Expand All @@ -113,9 +116,9 @@ const registerAuthEvents = (mainWindow) => {
});

await spaceClient.backupKeysByPassphrase({
type: 1, // 0 = PASSWORD; 1 = ETH
uuid: data.data.uuid,
passphrase: payload.torusRes.privateKey,
type: getKeyBackupType({ typeOfLogin: payload.torusRes.userInfo.typeOfLogin }),
});

await apiClient.identity.addEthAddress({
Expand Down
23 changes: 23 additions & 0 deletions public/electron/utils/get-key-backup-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { KeyBackupType } = require('@fleekhq/space-client/dist/definitions/space_pb');

const TYPE_OF_LOGIN = {
google: KeyBackupType.GOOGLE,
twitter: KeyBackupType.TWITTER,
password: KeyBackupType.PASSWORD,
passwordless: KeyBackupType.EMAIL,
};

/**
* Get number based on type of login
* @param {Object} opts
* @param {String} opts.typeOfLogin
*/
const getKeyBackupType = ({ typeOfLogin }) => {
if (typeof TYPE_OF_LOGIN[typeOfLogin] === 'undefined') {
return '';
}

return TYPE_OF_LOGIN[typeOfLogin];
};

module.exports = getKeyBackupType;
1 change: 1 addition & 0 deletions public/electron/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ module.exports.swapKeyValue = require('./swap-key-value');
module.exports.mapNotification = require('./map-notification');
module.exports.getAppTokenMetadata = require('./get-app-token-metadata');
module.exports.getRedirectPath = require('./get-redirect-path');
module.exports.getKeyBackupType = require('./get-key-backup-type');
7 changes: 5 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pickBy from 'lodash/pickBy';
import identity from 'lodash/identity';

const {
NODE_ENV,
REACT_APP_TORUS_NETWORK,
Expand All @@ -16,14 +19,14 @@ export default {
url: REACT_APP_WS_AUTH_CHALLENGE_URL,
},
torus: {
sdkConfig: {
sdkConfig: pickBy({
enableLogging: NODE_ENV !== 'production',
redirectToOpener: true,
redirectPathName: 'redirect.html',
baseUrl: REACT_APP_TORUS_PROVIDERS_REDIRECT_URL,
proxyContractAddress: REACT_APP_TORUS_PROXY_CONTRACT, // details for test net
network: REACT_APP_TORUS_NETWORK, // details for test net
},
}, identity),
providers: {
google: {
name: 'Google',
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1692,10 +1692,10 @@
"@ethersproject/properties" "^5.0.3"
"@ethersproject/strings" "^5.0.4"

"@fleekhq/space-client@^1.1.5":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@fleekhq/space-client/-/space-client-1.1.5.tgz#ed79f280f1d1cb1f9965289d25907c6a71c2cdf0"
integrity sha512-dkJseEFRCyELhdccdZwoTFQZPFCixOgRtGLWybb0fPKstQYKXU/2he5FduKVaur6G+rxXW6pNgwAqTo43wz8zA==
"@fleekhq/space-client@^1.1.7":
version "1.1.7"
resolved "https://registry.yarnpkg.com/@fleekhq/space-client/-/space-client-1.1.7.tgz#e38599d9b8fa331e9e551d2c6d4c786c2421eca1"
integrity sha512-GsvAmdg5zOxzFbFcFpiJsyb4CGzS4iR+sZ+m9rayGw87Vqkw1ythnShAzljS6Y50/vI0iZVYnFcScX+rH5v3pQ==
dependencies:
"@types/google-protobuf" "^3.7.2"
google-protobuf "^3.12.2"
Expand Down

0 comments on commit 01aa4ea

Please sign in to comment.