Skip to content

Commit

Permalink
feat: EdDSA Recovery Consolidation Support
Browse files Browse the repository at this point in the history
Adding support for EdDSA recovery consolidations
for the following coins: Ada and Dot.

Ticket: WP-570
  • Loading branch information
mohammadalfaiyazbitgo committed Sep 7, 2023
1 parent ce22212 commit cd4408e
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 115 deletions.
65 changes: 49 additions & 16 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {
AdaRecoveryConsolidationRecoveryOptions,
DotRecoveryConsolidationRecoveryOptions,
SolRecoveryConsolidationRecoveryOptions,
TrxConsolidationRecoveryOptions,
} from '../types';

process.env.DIST_ELECTRON = join(__dirname, '../..');
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist');
process.env.PUBLIC = app.isPackaged
Expand Down Expand Up @@ -238,15 +245,30 @@ async function createWindow() {
ipcMain.handle('recoverConsolidations', async (event, coin, params) => {
try {
switch (coin) {
case 'ada':
case 'tada':
case 'dot':
case 'tdot': {
const mpcCoin = sdk.coin(coin) as
| Ada
| Tada
| Dot
| Tdot;
return await mpcCoin.recoverConsolidations(params);
}
case 'trx':
case 'ttrx': {
// Batch Consolidations only implemented for Tron for now so have
// to reference Trx Coin directly instead of Basecoin;
const trxCoin = sdk.coin(coin) as Trx | Ttrx;
return await trxCoin.recoverConsolidations(params);
return await trxCoin.recoverConsolidations(
params as TrxConsolidationRecoveryOptions
);
}
default:
throw new Error(`Coin: ${coin} does not support consolidation recovery`);
throw new Error(
`Coin: ${coin} does not support consolidation recovery`
);
}
} catch (e) {
return new Error(handleSdkError(e));
Expand Down Expand Up @@ -310,22 +332,33 @@ async function createWindow() {
return Promise.resolve(sdkJson.user || sdkJson.token);
});

ipcMain.handle('createBroadcastableSweepTransaction', async (event, coin, parameters) => {
switch (coin) {
// Temporary measure till this is refactored into Basecoin
case 'ada':
case 'tada':
case 'dot':
case 'tdot':
case 'sol':
case 'tsol': {
const coinInstance = sdk.coin(coin) as Ada | Tada | Dot | Tdot | Sol | Tsol;
return coinInstance.createBroadcastableSweepTransaction(parameters);
ipcMain.handle(
'createBroadcastableSweepTransaction',
async (event, coin, parameters) => {
switch (coin) {
// Temporary measure till this is refactored into Basecoin
case 'ada':
case 'tada':
case 'dot':
case 'tdot':
case 'sol':
case 'tsol': {
const coinInstance = sdk.coin(coin) as
| Ada
| Tada
| Dot
| Tdot
| Sol
| Tsol;
return coinInstance.createBroadcastableSweepTransaction(parameters);
}
default:
return new Error(
`Coin: ${coin} does not support creating a broadcastable creation`
);
}
default:
return new Error(`Coin: ${coin} does not support creating a broadcastable creation`);
}
});
);
}

void app.whenReady().then(createWindow);
Expand Down
64 changes: 52 additions & 12 deletions electron/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,50 @@ import type {
RecoverFromWrongChainOptions,
RecoverParams,
} from '@bitgo/abstract-utxo';
// Recovery Consolidations only supported in tron for now.
import type { ConsolidationRecoveryOptions, ConsolidationRecoveryBatch } from '@bitgo/sdk-coin-trx';
import type {
ConsolidationRecoveryOptions as TrxConsolidationRecoveryOptions,
ConsolidationRecoveryBatch as TrxConsolidationRecoveryBatch,
} from '@bitgo/sdk-coin-trx';
import type { Chain, Hardfork } from '@ethereumjs/common';
import { contextBridge, ipcRenderer } from 'electron';
import type { ObjectEncodingOptions } from 'node:fs';
import {
AdaRecoveryConsolidationRecoveryBatch,
AdaRecoveryConsolidationRecoveryOptions,
BroadcastableSweepTransaction,
createAdaBroadcastableSweepTransactionParameters,
createDotBroadcastableSweepTransactionParameters, createSolBroadcastableSweepTransactionParameters,
createDotBroadcastableSweepTransactionParameters,
createSolBroadcastableSweepTransactionParameters,
DotRecoverConsolidationRecoveryBatch,
DotRecoveryConsolidationRecoveryOptions,
SolRecoverConsolidationRecoveryBatch,
SolRecoveryConsolidationRecoveryOptions,
} from '../types';

type User = { username: string };

type Commands = {
createBroadcastableSweepTransaction(
coin: string,
parameters: createAdaBroadcastableSweepTransactionParameters |
createDotBroadcastableSweepTransactionParameters |
createSolBroadcastableSweepTransactionParameters
): Promise<Error | BroadcastableSweepTransaction>
parameters:
| createAdaBroadcastableSweepTransactionParameters
| createDotBroadcastableSweepTransactionParameters
| createSolBroadcastableSweepTransactionParameters
): Promise<Error | BroadcastableSweepTransaction>;
recoverConsolidations(
coin: string,
params: ConsolidationRecoveryOptions
): Promise<Error | ConsolidationRecoveryBatch>;
params:
| TrxConsolidationRecoveryOptions
| AdaRecoveryConsolidationRecoveryOptions
| DotRecoveryConsolidationRecoveryOptions
| SolRecoveryConsolidationRecoveryOptions
): Promise<
| Error
| TrxConsolidationRecoveryBatch
| AdaRecoveryConsolidationRecoveryBatch
| DotRecoverConsolidationRecoveryBatch
| SolRecoverConsolidationRecoveryBatch
>,
writeFile(
file: string,
data: string,
Expand Down Expand Up @@ -120,10 +140,30 @@ const queries: Queries = {
};

const commands: Commands = {
createBroadcastableSweepTransaction(coin, parameters): Promise<Error | BroadcastableSweepTransaction> {
return ipcRenderer.invoke('createBroadcastableSweepTransaction', coin, parameters);
createBroadcastableSweepTransaction(
coin,
parameters
): Promise<Error | BroadcastableSweepTransaction> {
return ipcRenderer.invoke(
'createBroadcastableSweepTransaction',
coin,
parameters
);
},
recoverConsolidations(coin: string, params: ConsolidationRecoveryOptions): Promise<Error | ConsolidationRecoveryBatch> {
recoverConsolidations(
coin: string,
params:
| TrxConsolidationRecoveryOptions
| AdaRecoveryConsolidationRecoveryOptions
| DotRecoveryConsolidationRecoveryOptions
| SolRecoveryConsolidationRecoveryOptions
): Promise<
| Error
| TrxConsolidationRecoveryBatch
| AdaRecoveryConsolidationRecoveryBatch
| DotRecoverConsolidationRecoveryBatch
| SolRecoverConsolidationRecoveryBatch
> {
return ipcRenderer.invoke('recoverConsolidations', coin, params);
},
writeFile(file, data, options) {
Expand Down
11 changes: 11 additions & 0 deletions electron/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ConsolidationRecoveryBatch, ConsolidationRecoveryOptions } from '@bitgo/sdk-coin-trx';
import { Ada, Tada } from '@bitgo/sdk-coin-ada';
import { Dot, Tdot } from '@bitgo/sdk-coin-dot';
import { Sol, Tsol } from '@bitgo/sdk-coin-sol';
Expand All @@ -11,3 +12,13 @@ export type BroadcastableSweepTransaction = Awaited<ReturnType<
Dot['createBroadcastableSweepTransaction'] | Tdot['createBroadcastableSweepTransaction'] |
Sol ['createBroadcastableSweepTransaction'] | Tsol['createBroadcastableSweepTransaction']
>>;

export type AdaRecoveryConsolidationRecoveryOptions = Parameters<Ada['recoverConsolidations']>[0] | Parameters<Tada['recoverConsolidations']>[0];
export type DotRecoveryConsolidationRecoveryOptions = Parameters<Dot['recoverConsolidations']>[0] | Parameters<Tdot['recoverConsolidations']>[0];
export type SolRecoveryConsolidationRecoveryOptions = Parameters<Sol['recoverConsolidations']>[0] | Parameters<Tsol['recoverConsolidations']>[0];
export type TrxConsolidationRecoveryOptions = ConsolidationRecoveryOptions;

export type AdaRecoveryConsolidationRecoveryBatch = Awaited<ReturnType<Ada['recoverConsolidations'] | Tada['recoverConsolidations']>>;
export type DotRecoverConsolidationRecoveryBatch = Awaited<ReturnType<Dot['recoverConsolidations'] | Tdot['recoverConsolidations']>>;
export type SolRecoverConsolidationRecoveryBatch = Awaited<ReturnType<Sol['recoverConsolidations'] | Tsol['recoverConsolidations']>>;
export type TrxConsolidationRecoveryBatch = ConsolidationRecoveryBatch;
Loading

0 comments on commit cd4408e

Please sign in to comment.