Skip to content
Permalink
Browse files

Merge branch 'devops-1195' of https://github.com/input-output-hk/daed…

…alus into devops-1195
  • Loading branch information...
daniloprates committed Mar 13, 2019
2 parents 08d1116 + 48243c8 commit 33efea5448944a7745ba6651ce4a74d0f7e20413
@@ -1,6 +1,6 @@
{
"url": "https://github.com/input-output-hk/cardano-sl",
"rev": "b4be5cf965d8563e98f4e2f1c75b37a332f9d742",
"sha256": "13hj7a5l6k25a9inwybsgpfp0d2nn8l87278bfljjmhsvkijll9v",
"rev": "9692f115fbdd61486e17638ec51b58c2a54ec811",
"sha256": "0j8cfid1xjmw3pl5cz0qpxqjbfzz0c3wm1s9gfpgs7n90vnhnhcz",
"fetchSubmodules": false
}
@@ -59,7 +59,7 @@ export const addOrSetWalletsForScenario = function (wallet) {

export const importWalletWithFunds = async (client, { keyFilePath, password }) => (
await client.executeAsync((filePath, spendingPassword, done) => {
daedalus.api.ada.importWalletFromKey({ filePath, spendingPassword })
daedalus.api.ada.importWalletFromKeyFile({ filePath, spendingPassword })
.then(() => (
daedalus.stores.wallets.refreshWalletsData()
.then(done)
@@ -10,10 +10,7 @@ import type {
} from '../types/report-request.types';
import type { GeneratePaperWalletParams } from '../types/paper-wallet-request.types';
import type { CheckDiskSpaceResponse } from '../types/no-disk-space.types';
import type {
ExtractedWallet,
ExtractedWallets,
} from '../types/wallet-importer.types';
import type { ExtractedWallets } from '../types/wallet-importer.types';

/**
* Channel for loading an base64 encoded asset from within the `source/renderer` folder
@@ -77,23 +74,6 @@ export const ExtractWalletsChannelName = 'ExtractWalletsChannel';
export type ExtractWalletsRendererRequest = { secretKeyFilePath: string };
export type ExtractWalletsMainResponse = ExtractedWallets;

/**
* Channel for generating wallet key file
*/
export const GenerateKeyFileChannelName = 'GenerateKeyFileChannel';
export type GenerateKeyFileRendererRequest = {
wallet: ExtractedWallet,
filePath?: string,
};
export type GenerateKeyFileMainResponse = string;

/**
* Channel for deleting wallet key file
*/
export const DeleteKeyFileChannelName = 'DeleteKeyFileChannel';
export type DeleteKeyFileRendererRequest = { filePath: string };
export type DeleteKeyFileMainResponse = void;

/**
* Channel for matching extracted wallets passwords
*/
@@ -1,7 +1,7 @@
// @flow
export type ExtractedWallet = {
index: number,
raw: Array<Buffer>,
encryptedSecretKey: string,
passwordHash: string,
password: ?string,
balance: ?string,

This file was deleted.

Oops, something went wrong.
@@ -28,7 +28,7 @@ export const handleExtractWalletsRequests = () => {
keys.forEach((key, index) => {
wallets.push({
index: index + 1,
raw: key,
encryptedSecretKey: cbor.encode(key).toString('hex'),
passwordHash: key[1].toString('ascii'),
password: null,
balance: null,

This file was deleted.

Oops, something went wrong.
@@ -7,9 +7,7 @@ import parseRedemptionCodeApi from './parse-redemption-code-from-pdf';
import resizeWindowApi from './resize-window';
import loadAsset from './load-asset';
import getGpuStatus from './get-gpu-status';
import { handleDeleteKeyFileRequests } from './deleteKeyFileChannel';
import { handleExtractWalletsRequests } from './extractWalletsChannel';
import { handleGenerateKeyFileRequests } from './generateKeyFileChannel';
import { handleMatchWalletsPasswordsRequests } from './matchWalletsPasswordsChannel';
import { handleReportRequests } from './reportRequestChannel';
import { handlePaperWalletRequests } from './generatePaperWalletChannel';
@@ -23,9 +21,7 @@ export default (window: BrowserWindow) => {
resizeWindowApi(window);
loadAsset();
getGpuStatus();
handleDeleteKeyFileRequests();
handleExtractWalletsRequests();
handleGenerateKeyFileRequests();
handleMatchWalletsPasswordsRequests();
handleReportRequests();
handlePaperWalletRequests();
@@ -8,6 +8,5 @@ export default class WalletImporterActions {
extractWallets: Action<{ keyFile: File }> = new Action();
matchPasswords: Action<{ passwords: Array<string> }> = new Action();
matchPasswordsEnd: Action<any> = new Action();
downloadKeyFile: Action<{ wallet: ExtractedWallet, filePath: string }> = new Action();
importKeyFile: Action<{ wallet: ExtractedWallet }> = new Action();
}
@@ -33,10 +33,12 @@ import { redeemPaperVendedAda } from './transactions/requests/redeemPaperVendedA
import { resetWalletState } from './wallets/requests/resetWalletState';
import { changeSpendingPassword } from './wallets/requests/changeSpendingPassword';
import { deleteWallet } from './wallets/requests/deleteWallet';
import { exportWalletAsJSON } from './wallets/requests/exportWalletAsJSON';
import { importWalletAsJSON } from './wallets/requests/importWalletAsJSON';
import { exportWalletToJSONFile } from './wallets/requests/exportWalletToJSONFile';
import { importWalletFromJSONFile } from './wallets/requests/importWalletFromJSONFile';
import { getWallets } from './wallets/requests/getWallets';
import { importWalletAsKey } from './wallets/requests/importWalletAsKey';
import { getWalletBalance } from './wallets/requests/getWalletBalance';
import { importWalletFromKeyFile } from './wallets/requests/importWalletFromKeyFile';
import { importWalletFromSecretKey } from './wallets/requests/importWalletFromSecretKey';
import { createWallet } from './wallets/requests/createWallet';
import { restoreWallet } from './wallets/requests/restoreWallet';
import { updateWallet } from './wallets/requests/updateWallet';
@@ -113,15 +115,19 @@ import type {
import type {
AdaWallet,
AdaWallets,
WalletBalance,
CreateWalletRequest,
DeleteWalletRequest,
RestoreWalletRequest,
UpdateSpendingPasswordRequest,
ExportWalletToFileRequest,
GetWalletBalanceRequest,
GetWalletBalanceResponse,
GetWalletCertificateRecoveryPhraseRequest,
GetWalletRecoveryPhraseFromCertificateRequest,
ImportWalletFromKeyRequest,
ImportWalletFromKeyFileRequest,
ImportWalletFromFileRequest,
ImportWalletFromSecretKeyRequest,
UpdateWalletRequest
} from './wallets/types';

@@ -609,20 +615,20 @@ export default class AdaApi {
}
};

importWalletFromKey = async (
request: ImportWalletFromKeyRequest
importWalletFromKeyFile = async (
request: ImportWalletFromKeyFileRequest
): Promise<Wallet> => {
Logger.debug('AdaApi::importWalletFromKey called', { parameters: filterLogData(request) });
Logger.debug('AdaApi::importWalletFromKeyFile called', { parameters: filterLogData(request) });
const { filePath, spendingPassword: passwordString } = request;
const spendingPassword = passwordString ? encryptPassphrase(passwordString) : '';
try {
const importedWallet: AdaWallet = await importWalletAsKey(
const importedWallet: AdaWallet = await importWalletFromKeyFile(
this.config, { filePath, spendingPassword }
);
Logger.debug('AdaApi::importWalletFromKey success', { importedWallet });
Logger.debug('AdaApi::importWalletFromKeyFile success', { importedWallet });
return _createWalletFromServerData(importedWallet);
} catch (error) {
Logger.error('AdaApi::importWalletFromKey error', { error });
Logger.error('AdaApi::importWalletFromKeyFile error', { error });
if (error.message === 'WalletAlreadyExists') {
throw new WalletAlreadyImportedError(error);
}
@@ -639,9 +645,9 @@ export default class AdaApi {
const isKeyFile = filePath.split('.').pop().toLowerCase() === 'key';
try {
const importedWallet: AdaWallet = isKeyFile ? (
await importWalletAsKey(this.config, { filePath, spendingPassword })
await importWalletFromKeyFile(this.config, { filePath, spendingPassword })
) : (
await importWalletAsJSON(this.config, filePath)
await importWalletFromJSONFile(this.config, filePath)
);
Logger.debug('AdaApi::importWalletFromFile success', { importedWallet });
return _createWalletFromServerData(importedWallet);
@@ -654,6 +660,47 @@ export default class AdaApi {
}
};

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

getWalletBalance = async (
request: GetWalletBalanceRequest
): Promise<WalletBalance> => {
Logger.debug('AdaApi::getWalletBalance called');
const { encryptedSecretKey } = request;
try {
const walletBalance: GetWalletBalanceResponse =
await getWalletBalance(this.config, encryptedSecretKey);
Logger.debug('AdaApi::getWalletBalance success', { walletBalance });
const { balance, walletId } = walletBalance;
return {
balance: new BigNumber(balance).dividedBy(LOVELACES_PER_ADA),
walletId,
};
} catch (error) {
Logger.error('AdaApi::getWalletBalance error', { error });
throw new GenericApiError();
}
};

redeemAda = async (
request: RedeemAdaParams
): Promise<WalletTransaction> => {
@@ -781,7 +828,7 @@ export default class AdaApi {
const { walletId, filePath } = request;
Logger.debug('AdaApi::exportWalletToFile called', { parameters: filterLogData(request) });
try {
const response: Promise<[]> = await exportWalletAsJSON(
const response: Promise<[]> = await exportWalletToJSONFile(
this.config, { walletId, filePath }
);
Logger.debug('AdaApi::exportWalletToFile success', { response });
@@ -2,14 +2,14 @@
import type { RequestConfig } from '../../common/types';
import { request } from '../../utils/requestV0';

export type ExportWalletAsJSONParams = {
export type ExportWalletToJSONFileParams = {
walletId: string,
filePath: string,
};

export const exportWalletAsJSON = (
export const exportWalletToJSONFile = (
config: RequestConfig,
{ walletId, filePath }: ExportWalletAsJSONParams,
{ walletId, filePath }: ExportWalletToJSONFileParams,
): Promise<[]> => (
request({
method: 'POST',
@@ -0,0 +1,15 @@
// @flow
import type { RequestConfig } from '../../common/types';
import type { GetWalletBalanceResponse } from '../types';
import { request } from '../../utils/request';

export const getWalletBalance = (
config: RequestConfig,
encryptedSecretKey: string, // EncryptedSecretKey (hex-encoded)
): Promise<GetWalletBalanceResponse> => (
request({
method: 'POST',
path: '/api/internal/query-balance',
...config,
}, {}, encryptedSecretKey)
);
@@ -3,7 +3,7 @@ import type { RequestConfig } from '../../common/types';
import type { AdaWallet } from '../types';
import { request } from '../../utils/requestV0';

export const importWalletAsJSON = (
export const importWalletFromJSONFile = (
config: RequestConfig,
filePath: string,
): Promise<AdaWallet> => (
@@ -3,14 +3,14 @@ import type { RequestConfig } from '../../common/types';
import type { AdaWallet } from '../types';
import { request } from '../../utils/request';

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

export const importWalletAsKey = (
export const importWalletFromKeyFile = (
config: RequestConfig,
walletImportData: ImportWalletAsKey
walletImportData: ImportWalletFromKeyFile
): Promise<AdaWallet> => (
request({
method: 'POST',
@@ -0,0 +1,20 @@
// @flow
import type { RequestConfig } from '../../common/types';
import type { AdaWallet } from '../types';
import { request } from '../../utils/request';

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

export const importWalletFromSecretKey = (
config: RequestConfig,
walletImportData: ImportWalletFromSecretKey
): Promise<AdaWallet> => (
request({
method: 'POST',
path: '/api/internal/import-wallet',
...config,
}, {}, walletImportData)
);
Oops, something went wrong.

0 comments on commit 33efea5

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