Skip to content
Permalink
Browse files

[DEVOPS-1195] Integrate raw secret imports

  • Loading branch information...
nikolaglumac committed Mar 13, 2019
1 parent 8c3af4a commit 7e7c9ab188833a7c27cb1d6ff17e2aa6bd30f89b
@@ -38,6 +38,7 @@ import { importWalletAsJSON } from './wallets/requests/importWalletAsJSON';
import { getWallets } from './wallets/requests/getWallets';
import { getWalletBalance } from './wallets/requests/getWalletBalance';
import { importWalletAsKey } from './wallets/requests/importWalletAsKey';
import { importWalletAsRawSecret } from './wallets/requests/importWalletAsRawSecret';
import { createWallet } from './wallets/requests/createWallet';
import { restoreWallet } from './wallets/requests/restoreWallet';
import { updateWallet } from './wallets/requests/updateWallet';
@@ -126,6 +127,7 @@ import type {
GetWalletRecoveryPhraseFromCertificateRequest,
ImportWalletFromKeyRequest,
ImportWalletFromFileRequest,
ImportWalletFromRawSecretRequest,
UpdateWalletRequest
} from './wallets/types';

@@ -658,6 +660,27 @@ export default class AdaApi {
}
};

importWalletFromRawSecret = async (
request: ImportWalletFromRawSecretRequest
): Promise<Wallet> => {
Logger.debug('AdaApi::importWalletFromRawSecret called');
const { rawSecret, spendingPassword: passwordString } = request;
const spendingPassword = passwordString ? encryptPassphrase(passwordString) : '';
try {
const importedWallet: AdaWallet = await importWalletAsRawSecret(
this.config, { rawSecret, spendingPassword }
);
Logger.debug('AdaApi::importWalletFromRawSecret success', { importedWallet });
return _createWalletFromServerData(importedWallet);
} catch (error) {
Logger.error('AdaApi::importWalletFromRawSecret error', { error });
if (error.message === 'WalletAlreadyExists') {
throw new WalletAlreadyImportedError(error);
}
throw new WalletFileImportError(error);
}
};

getWalletBalance = async (
request: GetWalletBalanceRequest
): Promise<WalletBalance> => {
@@ -0,0 +1,20 @@
// @flow
import type { RequestConfig } from '../../common/types';
import type { AdaWallet } from '../types';
import { request } from '../../utils/request';

export type ImportWalletAsRawSecret = {
rawSecret: string,
spendingPassword?: string,
};

export const importWalletAsRawSecret = (
config: RequestConfig,
walletImportData: ImportWalletAsRawSecret
): Promise<AdaWallet> => (
request({
method: 'POST',
path: '/api/internal/import-wallet',
...config,
}, {}, walletImportData)
);
@@ -71,11 +71,17 @@ export type UpdateWalletRequest = {
assuranceLevel: WalletAssuranceLevel,
name: string
};

export type ImportWalletFromKeyRequest = {
filePath: string,
spendingPassword: ?string,
};

export type ImportWalletFromRawSecretRequest = {
rawSecret: string,
spendingPassword: ?string,
};

export type ImportWalletFromFileRequest = {
filePath: string,
spendingPassword: ?string,
@@ -24,7 +24,7 @@ export default class WalletImporterStore extends Store {
@observable extractedWallets: ExtractedWallets = [];

/* eslint-disable max-len */
@observable importFromKeyRequest: Request<Wallet> = new Request(this.api.ada.importWalletFromKey);
@observable importWalletFromRawSecretRequest: Request<Wallet> = new Request(this.api.ada.importWalletFromRawSecret);
@observable getWalletBalanceRequest: Request<WalletBalance> = new Request(this.api.ada.getWalletBalance);
/* eslint-disable max-len */

@@ -103,7 +103,7 @@ export default class WalletImporterStore extends Store {
const { wallet } = params;
const rawSecret = await generateRawSecretChannel.send({ wallet: toJS(wallet) });
const spendingPassword = wallet.password;
const importedWallet = await this.importFromKeyRequest.execute({
const importedWallet = await this.importWalletFromRawSecretRequest.execute({
rawSecret, spendingPassword,
}).promise;
if (!importedWallet) throw new Error('Imported wallet was not received correctly');

0 comments on commit 7e7c9ab

Please sign in to comment.
You can’t perform that action at this time.