Skip to content
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
42 changes: 12 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@
"@waves/ledger": "^3.4.0",
"@waves/marshall": "^0.8.0",
"@waves/oracle-data": "^0.0.6",
"@waves/signature-adapter": "^5.1.11",
"@waves/signature-adapter": "^5.2.0",
"@waves/ts-types": "0.0.2",
"@waves/waves-browser-bus": "^0.1.5",
"@waves/waves-transactions": "^3.14.3",
"@waves/waves-transactions": "^3.16.3",
"angular": "1.6.6",
"angular-animate": "1.6.6",
"angular-aria": "1.6.6",
Expand Down
7 changes: 7 additions & 0 deletions src/modules/app/services/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
* @type {string}
*/
encryptedSeed;
/**
* @type {string}
*/
encryptedPrivateKey;
/**
* @type {string}
*/
Expand Down Expand Up @@ -362,6 +366,7 @@
* @param {string} data.name
* @param {string} data.id
* @param {string} data.encryptedSeed
* @param {string} data.encryptedPrivateKey
* @param {string} data.publicKey
* @param {string} data.password
* @param {string} data.userType
Expand All @@ -384,6 +389,7 @@
name: data.name,
userType: data.userType,
encryptedSeed: data.encryptedSeed,
encryptedPrivateKey: data.encryptedPrivateKey,
publicKey: data.publicKey,
settings: {
termsAccepted: false,
Expand Down Expand Up @@ -597,6 +603,7 @@
this.name = null;
this.publicKey = null;
this.encryptedSeed = null;
this.encryptedPrivateKey = null;
this.userType = null;
this.settings = Object.create(null);
this.lastLogin = Date.now();
Expand Down
9 changes: 5 additions & 4 deletions src/modules/import/templates/import.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@
w-analytics event="'Import Backup Click'" event-target="'ui'">
<div class="import-modal__icon import-modal__icon-beta"></div>
<div class="import-modal__content">
<div class="body-1 margin-1 import-modal__content-title" w-i18n="wavesSeedClient"></div>
<div class="body-2 basic-500 import-modal__content-text" w-i18n="wavesSeedClientDescription"></div>
<div class="body-1 margin-1 import-modal__content-title" w-i18n="seedAndKey"></div>
<div class="body-2 basic-500 import-modal__content-text"
w-i18n="seedAndKeyDescription"></div>
</div>
</div>
<div ng-if="isDesktop" class="import-modal__block" ui-sref="ledger"
w-analytics event="'Import Ledger Click'" event-target="'ui'">
<div class="import-modal__icon import-modal__icon-ledger"></div>
<div class="import-modal__content">
<div class="body-1 margin-1 import-modal__content-title" w-i18n="LedgerClient"></div>
<div class="body-2 basic-500 import-modal__content-text" w-i18n="ledgerDescription"></div>
<div class="body-2 basic-500 import-modal__content-text margin-05" w-i18n="ledgerDescription"></div>
</div>
</div>
<w-web-only ng-if="isNotPhone" w-web-only-class="import-modal__block" ui-sref="keeper">
<w-analytics event="'Import Keeper Click'" event-target="'ui'" class="import-modal__block-w">
<div class="import-modal__icon import-modal__icon-keeper"></div>
<div class="import-modal__content">
<div class="body-1 margin-1 import-modal__content-title" w-i18n="KeeperClient"></div>
<div class="body-2 basic-500 import-modal__content-text" w-i18n="keeperDescription"></div>
<div class="body-2 basic-500 import-modal__content-text margin-05" w-i18n="keeperDescription"></div>
</div>
</w-analytics>
</w-web-only>
Expand Down
104 changes: 91 additions & 13 deletions src/modules/restore/controllers/RestoreCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
'use strict';

const analytics = require('@waves/event-sender');
const { validators, libs } = require('@waves/waves-transactions');
const { isPublicKey } = validators;
const { address, publicKey } = libs.crypto;
const TABS = {
seed: 'seed',
key: 'key'
};

/**
* @param Base
Expand All @@ -17,32 +24,30 @@

constructor() {
super($scope);
$scope.TABS = TABS;

this.seedForm = null;
/**
* @type {string}
*/
this.address = '';
this.keyForm = null;
/**
* @type {string}
*/
this.seed = '';
/**
* @type {string}
*/
this.name = '';
this.key = '';
/**
* @type {string}
*/
this.encryptedSeed = '';
this.address = '';
/**
* @type {string}
*/
this.password = '';
this.name = '';
/**
* @type {string}
*/
this.restoreType = '';
this.password = '';
/**
* @type {boolean}
*/
Expand All @@ -51,38 +56,58 @@
* @type {number}
*/
this.activeStep = 0;
/**
* @type {string[]}
*/
this.tabs = Object.values(TABS);
/**
* @type {string}
*/
this.activeTab = TABS.seed;

this.observe('seed', this._onChangeSeed);
this.observeOnce('seedForm', () => {
this.receive(utils.observe(this.seedForm, '$valid'), this._onChangeSeed, this);
this.receive(utils.observe(this.seedForm, '$valid'), () => {
if (this.activeTab === TABS.seed) {
this._onChangeSeed();
}
});
});
this.observe('key', this._onChangeKey);
this.observeOnce('keyForm', () => {
this.receive(utils.observe(this.keyForm, '$valid'), () => {
if (this.activeTab === TABS.key) {
this._onChangeKey();
}
});
});
this.observe('activeTab', this._onChangeActiveTab);
}

showTutorialModals() {
return modalManager.showTutorialModals();
}

restore() {

if (!this.saveUserData) {
this.password = Date.now().toString();
} else {
analytics.send({ name: 'Import Backup Protect Your Account Continue Click', target: 'ui' });
}

const encryptedSeed = new ds.Seed(this.seed, window.WavesApp.network.code).encrypt(this.password);
const { encrypted, type } = this._getEncryptedAndType();
const userSettings = user.getDefaultUserSettings({ termsAccepted: false });

const newUser = {
userType: this.restoreType,
userType: type,
address: this.address,
name: this.name,
password: this.password,
id: this.userId,
path: this.userPath,
settings: userSettings,
saveToStorage: this.saveUserData,
encryptedSeed
...encrypted
};

const api = ds.signature.getDefaultSignatureApi(newUser);
Expand Down Expand Up @@ -116,6 +141,13 @@
return modalManager.showImportAccountsModal();
}

/**
* @param {string} tab
*/
setActiveTab(tab) {
this.activeTab = tab;
}

/**
* @private
*/
Expand All @@ -127,6 +159,52 @@
}
}

/**
* @private
*/
_onChangeKey() {
if (this.keyForm.$valid && isPublicKey(this.key)) {
const pubKey = publicKey({ privateKey: this.key });
this.address = address({ publicKey: pubKey }, window.WavesApp.network.code);
} else {
this.address = '';
}
}

/**
* @private
*/
_onChangeActiveTab() {
const tab = this.activeTab[0].toUpperCase() + this.activeTab.substring(1);
this[`_onChange${tab}`]();
}

/**
* @return {{encrypted: {encryptedSeed: string}, type: string}|
* {encrypted: {encryptedPrivateKey: string}, type: string}}
* @private
*/
_getEncryptedAndType() {
switch (this.activeTab) {
case TABS.key:
return ({
encrypted: {
encryptedPrivateKey: new ds.Seed(this.key, window.WavesApp.network.code)
.encrypt(this.password)
},
type: 'privateKey'
});
default:
return ({
encrypted: {
encryptedSeed: new ds.Seed(this.seed, window.WavesApp.network.code)
.encrypt(this.password)
},
type: 'seed'
});
}
}

}

return new RestoreCtrl();
Expand Down
Loading