Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDW-639] Fund5 voting registration with Ledger #2538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6527813
[DDW-639] Introduce voting registration with Ledger devices INIT
tomislavhoracek Apr 27, 2021
be58650
[DDW-639] Add auxiliary data to Ledger signing and initiate voting wi…
tomislavhoracek Apr 30, 2021
fe16133
[DDW-639] Fix voting meta CBORizing and apply to txBody hash
tomislavhoracek May 18, 2021
b147cdc
[DDW-639] Fix failing tx caused by cborizing txBody with wrong HW vot…
tomislavhoracek May 21, 2021
56a9c49
[DDW-639] Merges-in latest develop branch and fix conflicts
tomislavhoracek May 21, 2021
82887f7
[DDW-639] Improved serialization logic with voting meta
tomislavhoracek May 26, 2021
c8dfe9f
[DDW-639] yarn.lock fix
tomislavhoracek May 26, 2021
5e0e62a
[DDW-639] yarn.lock - Remove integrity hashes
tomislavhoracek May 26, 2021
fe15fdb
[DDW-639] Remove logs and unnecessary methods
tomislavhoracek May 26, 2021
2485483
[DDW-639] Isolate auxiliary data constructor to shelleyledger helpers
tomislavhoracek May 26, 2021
8333779
[DDW-639] Fix eslint issues
tomislavhoracek May 26, 2021
24923d2
[DDW-639] Add proper HW Voting types and fix flow issus + code cleanup
tomislavhoracek May 26, 2021
f16336e
[DDW-639] Run prettier
tomislavhoracek May 26, 2021
a6affb8
[DDW-639] Update min supported Cardano App version and enable on Test…
tomislavhoracek May 26, 2021
c584df5
[DDW-639] Disable Voting for Trezor wallets
tomislavhoracek May 26, 2021
18e6d00
[DDW-639] Merges-in latest develop branch and fix conflicts
tomislavhoracek Jun 9, 2021
877fa9e
[DDW-639] Update CHANGELOG
tomislavhoracek Jun 9, 2021
7e62237
[DDW-639] Merges-in latest develop branch and fix conflict
tomislavhoracek Jun 18, 2021
362bf48
Merge branch 'develop' into feature/ddw-639-fund5-voting-registration…
tomislavhoracek Jun 25, 2021
b30d224
[DDW-639] Testing data with logs for Adrestia - TO REMOVE
tomislavhoracek Jul 2, 2021
d16321f
[DDW-639] Merges-in latest develop branch and fix conflicts
tomislavhoracek Jul 5, 2021
31438ee
[DDW-639] Coin selection signature placeholder
tomislavhoracek Jul 5, 2021
810ad9c
[DDW-639] Improve submitting and error handlers + code cleanup / impr…
tomislavhoracek Jul 5, 2021
c74c896
[DDW-639] Add fixed temp active voting wallet ID to hw store to avoid…
tomislavhoracek Jul 5, 2021
eeb386c
Merge branch 'develop' into feature/ddw-639-fund5-voting-registration…
tomislavhoracek Jul 5, 2021
a118fc6
[DDW-639] Update CHANGELOG and revert voting config
tomislavhoracek Jul 6, 2021
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

## vNext

### Features

- Added voting registration with Ledger ([PR 2538](https://github.com/input-output-hk/daedalus/pull/2538))

## 4.2.0-FC1

### Features
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"yarn-lockfile": "1.1.1"
},
"dependencies": {
"@cardano-foundation/ledgerjs-hw-app-cardano": "3.0.0",
"@cardano-foundation/ledgerjs-hw-app-cardano": "3.1.0",
"@iohk-jormungandr/wallet-js": "0.5.0-pre7",
"aes-js": "3.1.2",
"bech32": "2.0.0",
Expand Down
24 changes: 22 additions & 2 deletions source/common/types/hardware-wallets.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ export type LedgerSignTransactionOutputsType =
| []
| Array<LedgerOutputTypeAddress | LedgerOutputTypeChange>;

export type LedgerAuxiliaryDataType = {
type: string,
params: {
votingPublicKeyHex: string,
stakingPath: BIP32Path,
rewardsDestination: {
type: number,
params: {
stakingPath: BIP32Path,
},
},
nonce: string,
},
};

export type TrezorSignTransactionInputType = {
path: string,
prev_hash: number,
Expand Down Expand Up @@ -230,11 +245,11 @@ export type LedgerSignTransactionRequest = {
protocolMagic: number,
certificates: Array<?Certificate>,
withdrawals: Array<?Withdrawal>,
auxiliaryData: ?string,
reset?: boolean,
devicePath: ?string,
validityIntervalStartStr?: string,
validityIntervalStartStr?: ?string, // It is disabled for now
signingMode: string,
auxiliaryData: ?LedgerAuxiliaryDataType,
};

export type TrezorSignTransactionRequest = {
Expand All @@ -254,6 +269,11 @@ export type TrezorSignTransactionRequest = {
export type LedgerSignTransactionResponse = {
txHashHex: string,
witnesses: Array<Witness>,
auxiliaryDataSupplement?: {
catalystRegistrationSignatureHex: string,
auxiliaryDataHashHex: string,
type: 'catalyst_registration',
},
};

export type TrezorSignTransactionResponse = {
Expand Down
4 changes: 1 addition & 3 deletions source/main/ipc/getHardwareWalletChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ export const handleHardwareWalletRequests = async (
}
});

// @TODO - validityIntervalStartStr is not working with Cardano App 2.1.0
// @TODO - validityIntervalStart is not working with Cardano App 2.1.0
signTransactionLedgerChannel.onRequest(async (params) => {
const {
inputs,
Expand All @@ -695,7 +695,6 @@ export const handleHardwareWalletRequests = async (
withdrawals,
auxiliaryData,
devicePath,
// validityIntervalStartStr,
signingMode,
} = params;
logger.info('[HW-DEBUG] SIGN Ledger transaction');
Expand All @@ -721,7 +720,6 @@ export const handleHardwareWalletRequests = async (
certificates,
withdrawals,
auxiliaryData,
// validityIntervalStart,
},
});
return Promise.resolve(signedTransaction);
Expand Down
2 changes: 1 addition & 1 deletion source/renderer/app/actions/voting-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class VotingActions {
selectWallet: Action<string> = new Action();
sendTransaction: Action<{
amount: number,
passphrase: string,
passphrase: ?string,
}> = new Action();
generateQrCode: Action<number> = new Action();
saveAsPDF: Action<any> = new Action();
Expand Down
5 changes: 5 additions & 0 deletions source/renderer/app/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import type {
CreateExternalTransactionResponse,
GetWithdrawalsRequest,
GetWithdrawalsResponse,
VotingMetadataType,
ICOPublicKeyParams,
} from './transactions/types';

Expand Down Expand Up @@ -1027,6 +1028,7 @@ export default class AdaApi {
rewardsBalance: BigNumber,
payments?: CoinSelectionsPaymentRequestType,
delegation?: CoinSelectionsDelegationRequestType,
metadata?: VotingMetadataType,
}): Promise<CoinSelectionsResponse> => {
logger.debug('AdaApi::selectCoins called', {
parameters: filterLogData(request),
Expand All @@ -1038,6 +1040,7 @@ export default class AdaApi {
walletBalance,
availableBalance,
rewardsBalance,
metadata,
} = request;
try {
let data;
Expand All @@ -1061,6 +1064,7 @@ export default class AdaApi {
},
],
withdrawal: TransactionWithdrawal,
metadata: metadata || null,
};
} else {
throw new Error('Missing parameters!');
Expand Down Expand Up @@ -1169,6 +1173,7 @@ export default class AdaApi {
fee: fee.dividedBy(LOVELACES_PER_ADA),
deposits: deposits.dividedBy(LOVELACES_PER_ADA),
depositsReclaimed: depositsReclaimed.dividedBy(LOVELACES_PER_ADA),
metadata: response.metadata || null,
};

logger.debug('AdaApi::selectCoins success', { extendedResponse });
Expand Down
3 changes: 3 additions & 0 deletions source/renderer/app/api/transactions/requests/selectCoins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import type {
TransactionPaymentData,
CoinSelectionAmount,
TransactionWithdrawalType,
VotingMetadataType,
} from '../types';
import type { DelegationAction } from '../../../types/stakingTypes';
import { request } from '../../utils/request';

export type PaymentsType = {
payments: Array<TransactionPaymentData>,
withdrawal?: TransactionWithdrawalType,
metadata?: VotingMetadataType,
};

export type DelegationType = {
Expand Down Expand Up @@ -60,6 +62,7 @@ export type SelectCoinsResponseType = {
quantity: number,
unit: WalletUnits.LOVELACE,
}>,
metadata?: string,
};

export const selectCoins = (
Expand Down
54 changes: 54 additions & 0 deletions source/renderer/app/api/transactions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { WalletUnits } from '../../domains/Wallet';
import type { DelegationAction } from '../../types/stakingTypes';
import type { ApiTokens } from '../assets/types';
import type { TransactionMetadata } from '../../types/TransactionMetadata';
import type { PathRoleIdentityType } from '../../utils/hardwareWalletUtils';

export type TransactionAmount = {
quantity: number,
Expand Down Expand Up @@ -239,6 +240,7 @@ export type CoinSelectionsPaymentRequestType = {
address: string,
amount: number,
assets?: ApiTokens,
metadata?: VotingMetadataType,
};

export type CoinSelectionsRequest =
Expand All @@ -253,6 +255,7 @@ export type CoinSelectionsResponse = {
depositsReclaimed: BigNumber,
withdrawals: Array<CoinSelectionWithdrawal>,
fee: BigNumber,
metadata: ?string,
};

export type CreateExternalTransactionRequest = {
Expand Down Expand Up @@ -282,3 +285,54 @@ export type ICOPublicKeyParams = {
};

export type CoinSelectionAssetsType = Array<Asset>;

export type VotingMetaIndexType = 61284 | 61285;

export const VotingMetaIndexes: {
VOTING_REGISTRATION: VotingMetaIndexType,
VOTING_SIGNATURE: VotingMetaIndexType,
} = {
VOTING_REGISTRATION: 61284,
VOTING_SIGNATURE: 61285,
};

export type VotingMetaKeyValuePairString = {
[key: 'string']: string,
};
export type VotingMetaKeyValuePairInt = {
[key: 'int']: number,
};
export type VotingMetaKeyValuePairBytes = {
[key: 'bytes']: string,
};
export type VotingMetaKeyValuePairMap = {
[key: 'int']: number,
};

export type VotingMetaKeyType = 'string' | 'int' | 'bytes' | 'list' | 'map';

export type VotingMetaKeyValuePair = {
[key: 'k' | 'v']:
| VotingMetaKeyValuePairString
| VotingMetaKeyValuePairInt
| VotingMetaKeyValuePairBytes,
};

export type VotingMetaRegistrationType = {
[key: 'map']: Array<VotingMetaKeyValuePair>,
};

export type VotingMetadataType = {
[key: VotingMetaIndexType]: VotingMetaRegistrationType,
};

export type VotingDataType = {
stakeAddress: string,
stakeAddressHex: string,
votingKey: string,
stakeKey: string,
role: PathRoleIdentityType,
index: string,
metadata: VotingMetadataType,
nonce: number,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import StakePool from '../../domains/StakePool';
import LocalizableError from '../../i18n/LocalizableError';
import Wallet from '../../domains/Wallet';

import type { HwDeviceStatus } from '../../domains/Wallet';

type Props = {
stepsList: Array<string>,
activeStep: number,
Expand All @@ -35,9 +37,12 @@ type Props = {
isTransactionConfirmed: boolean,
transactionConfirmations: number,
transactionError: ?LocalizableError,
isTrezor: boolean,
isHardwareWallet: boolean,
onDownloadPDF: Function,
onRestart: Function,
onExternalLinkClick: Function,
hwDeviceStatus: HwDeviceStatus,
};

@observer
Expand Down Expand Up @@ -68,6 +73,9 @@ export default class VotingRegistrationDialogWizard extends Component<Props> {
onExternalLinkClick,
onClose,
onBack,
hwDeviceStatus,
isTrezor,
isHardwareWallet,
} = this.props;

const selectedWalletId = get(selectedWallet, 'id', null);
Expand All @@ -87,6 +95,8 @@ export default class VotingRegistrationDialogWizard extends Component<Props> {
onSelectWallet={onSelectWallet}
isWalletAcceptable={isWalletAcceptable}
getStakePoolById={getStakePoolById}
isTrezor={isTrezor}
isHardwareWallet={isHardwareWallet}
/>
);
break;
Expand All @@ -103,6 +113,10 @@ export default class VotingRegistrationDialogWizard extends Component<Props> {
onConfirm={onSubmit}
onBack={onBack}
onExternalLinkClick={onExternalLinkClick}
hwDeviceStatus={hwDeviceStatus}
selectedWallet={selectedWallet}
isTrezor={isTrezor}
isHardwareWallet={isHardwareWallet}
/>
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type Props = {
selectedWalletId: ?string,
isWalletAcceptable: Function,
getStakePoolById: Function,
isHardwareWallet: boolean,
isTrezor: boolean,
};

type State = {
Expand Down Expand Up @@ -122,6 +124,8 @@ export default class VotingRegistrationStepsChooseWallet extends Component<
isWalletAcceptable,
numberOfStakePools,
getStakePoolById,
isHardwareWallet,
isTrezor,
} = this.props;

const buttonLabel = intl.formatMessage(messages.continueButtonLabel);
Expand All @@ -130,24 +134,18 @@ export default class VotingRegistrationStepsChooseWallet extends Component<
(wallet: Wallet) => wallet && wallet.id === selectedWalletId
);

const { amount, reward, isLegacy, isHardwareWallet, isRestoring } =
selectedWallet || {};
const { amount, reward, isLegacy, isRestoring } = selectedWallet || {};

let errorMessage;
if (
selectedWallet &&
!isWalletAcceptable(
isLegacy,
isHardwareWallet,
isRestoring,
amount,
reward
)
!isWalletAcceptable(isLegacy, isRestoring, amount, reward)
) {
// Wallet is a legacy wallet
if (isLegacy) errorMessage = messages.errorLegacyWallet;
// Wallet is a hardware wallet
else if (isHardwareWallet) errorMessage = messages.errorHardwareWallet;
// Wallet is a hardware wallet (Trezor device type)
else if (isHardwareWallet && isTrezor)
errorMessage = messages.errorHardwareWallet;
// Wallet is restoring
else if (isRestoring) errorMessage = messages.errorRestoringWallet;
// Wallet only has Reward balance
Expand Down
Loading