Skip to content

Commit

Permalink
[DDW-735] Introduce an Hardware Wallets support for all non-public te…
Browse files Browse the repository at this point in the history
…stnets
  • Loading branch information
tomislavhoracek committed Sep 14, 2021
1 parent e94535d commit 37524be
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 40 deletions.
3 changes: 3 additions & 0 deletions source/common/utils/environmentCheckers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { upperFirst } from 'lodash';
import {
ALONZO_PURPLE,
SHELLEY_QA,
DEVELOPMENT,
LINUX,
MAC_OS,
Expand Down Expand Up @@ -54,6 +55,8 @@ export const checkIsMainnet = (network: string) => network === MAINNET;
export const checkIsTestnet = (network: string) => network === TESTNET;
export const checkIsAlonzoPurple = (network: string) =>
network === ALONZO_PURPLE;
export const checkIsShelleyQA = (network: string) =>
network === SHELLEY_QA;
export const checkIsStaging = (network: string) => network === STAGING;
export const checkIsSelfnode = (network: string) => network === SELFNODE;
export const checkIsDevelopment = (network: string) => network === DEVELOPMENT;
Expand Down
5 changes: 5 additions & 0 deletions source/main/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DEVELOPMENT, OS_NAMES } from '../common/types/environment.types';
import {
evaluateNetwork,
checkIsAlonzoPurple,
checkIsShelleyQA,
checkIsDev,
checkIsTest,
checkIsProduction,
Expand Down Expand Up @@ -34,6 +35,7 @@ const isMainnet = checkIsMainnet(NETWORK);
const isStaging = checkIsStaging(NETWORK);
const isTestnet = checkIsTestnet(NETWORK);
const isAlonzoPurple = checkIsAlonzoPurple(NETWORK);
const isShelleyQA = checkIsShelleyQA(NETWORK);
const isSelfnode = checkIsSelfnode(NETWORK);
const isDevelopment = checkIsDevelopment(NETWORK);
const isWatchMode = process.env.IS_WATCH_MODE;
Expand All @@ -55,6 +57,7 @@ const MOBX_DEV_TOOLS = process.env.MOBX_DEV_TOOLS || false;
const isMacOS = checkIsMacOS(PLATFORM);
const isWindows = checkIsWindows(PLATFORM);
const isLinux = checkIsLinux(PLATFORM);
const isNonPublicTestnet = isAlonzoPurple || isShelleyQA;

/* ==================================================================
= Compose environment =
Expand All @@ -75,6 +78,7 @@ export const environment: Environment = Object.assign(
isStaging,
isTestnet,
isAlonzoPurple,
isShelleyQA,
isSelfnode,
isDevelopment,
isWatchMode,
Expand All @@ -94,6 +98,7 @@ export const environment: Environment = Object.assign(
isLinux,
isBlankScreenFixActive,
keepLocalClusterRunning,
isNonPublicTestnet,
},
process.env
);
37 changes: 27 additions & 10 deletions source/renderer/app/config/hardwareWalletsConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const { isMainnet, isTestnet } = global.environment;
// @flow
import { get } from 'lodash';
import type { Network } from '../../../common/types/environment.types';

const { isMainnet, isTestnet, isNonPublicTestnet } = global.environment;

export const HARDENED_HEX = 0x80000000;
export const HARDENED = 2147483648;
Expand All @@ -9,21 +13,29 @@ export const DEFAULT_ADDRESS_INDEX = 0;

export const HW_SHELLEY_CONFIG = {
NETWORK: {
MAINNET: {
name: 'mainnet',
mainnet: {
networkId: 1,
networkName: 'mainnet',
protocolMagic: 764824073,
trezorProtocolMagic: 764824073,
eraStartSlot: 4492800,
ttl: 3600,
},
TESTNET: {
name: 'testnet',
testnet: {
networkId: 0,
networkName: 'testnet',
protocolMagic: 1097911063,
trezorProtocolMagic: 1097911063,
eraStartSlot: 4492800,
ttl: 3600,
},
shelley_qa: {
networkId: 0,
networkName: 'testnet',
protocolMagic: 3,
trezorProtocolMagic: 3,
},
alonzo_purple: {
networkId: 0,
networkName: 'testnet',
protocolMagic: 8,
trezorProtocolMagic: 8,
},
},
DEFAULT_DERIVATION_PATH: [
Expand Down Expand Up @@ -80,6 +92,11 @@ export const isTrezorEnabled = true;
export const isLedgerEnabled = true;

export const isHardwareWalletSupportEnabled =
(isMainnet || isTestnet) && (isTrezorEnabled || isLedgerEnabled);
(isMainnet || isTestnet || isNonPublicTestnet) && (isTrezorEnabled || isLedgerEnabled);

export const isHardwareWalletIndicatorEnabled = false;

export const getHardwareWalletsNetworkConfig = (network: Network) => {
const networkConfig = get(HW_SHELLEY_CONFIG, ['NETWORK', network], {});
return networkConfig;
};
43 changes: 13 additions & 30 deletions source/renderer/app/stores/HardwareWalletsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { HwDeviceStatuses } from '../domains/Wallet';
import WalletAddress from '../domains/WalletAddress';
import { toJS } from '../../../common/utils/helper';
import {
HW_SHELLEY_CONFIG,
SHELLEY_PURPOSE_INDEX,
ADA_COIN_TYPE,
MINIMAL_TREZOR_FIRMWARE_VERSION,
Expand All @@ -21,6 +20,7 @@ import {
isHardwareWalletSupportEnabled,
isTrezorEnabled,
isLedgerEnabled,
getHardwareWalletsNetworkConfig,
} from '../config/hardwareWalletsConfig';
import { TIME_TO_LIVE } from '../config/txnsConfig';
import {
Expand Down Expand Up @@ -160,6 +160,9 @@ const useCardanoAppInterval = (
addressVerification
);

const { network } = global.environment;
const networkConfig = getHardwareWalletsNetworkConfig(network);

export default class HardwareWalletsStore extends Store {
@observable selectCoinsRequest: Request<CoinSelectionsResponse> = new Request(
this.api.ada.selectCoins
Expand Down Expand Up @@ -262,7 +265,7 @@ export default class HardwareWalletsStore extends Store {

initLedger = async () => {
logger.debug(
`[HW-DEBUG] HWStore - initLedger() | isHardwareWalletSupportEnabled=${isHardwareWalletSupportEnabled} isLedgerEnabled=${isLedgerEnabled}`
`[HW-DEBUG] HWStore - initLedger() | isHardwareWalletSupportEnabled=${isHardwareWalletSupportEnabled.toString()} isLedgerEnabled=${isLedgerEnabled.toString()}`
);
if (isHardwareWalletSupportEnabled && isLedgerEnabled) {
logger.debug('[HW-DEBUG] HWStore - start ledger');
Expand Down Expand Up @@ -1131,7 +1134,6 @@ export default class HardwareWalletsStore extends Store {
}) => {
logger.debug('[HW-DEBUG] - VERIFY Address');
const { address, path, isTrezor } = params;
const { isMainnet } = this.environment;

this.hwDeviceStatus = HwDeviceStatuses.VERIFYING_ADDRESS;
this.tempAddressToVerify = params;
Expand All @@ -1142,12 +1144,8 @@ export default class HardwareWalletsStore extends Store {
addressType: AddressType.BASE,
spendingPathStr: address.spendingPath,
stakingPathStr: `${SHELLEY_PURPOSE_INDEX}'/${ADA_COIN_TYPE}'/0'/2/0`,
networkId: isMainnet
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.networkId
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.networkId,
protocolMagic: isMainnet
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.protocolMagic
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.protocolMagic,
networkId: networkConfig.networkId,
protocolMagic: networkConfig.protocolMagic,
});

if (derivedAddress === address.id) {
Expand Down Expand Up @@ -1239,7 +1237,6 @@ export default class HardwareWalletsStore extends Store {
}) => {
logger.debug('[HW-DEBUG] - SHOW Address');
const { address, path, isTrezor } = params;
const { isMainnet } = this.environment;

try {
await showAddressChannel.request({
Expand All @@ -1248,12 +1245,8 @@ export default class HardwareWalletsStore extends Store {
addressType: AddressType.BASE,
spendingPathStr: address.spendingPath,
stakingPathStr: `${SHELLEY_PURPOSE_INDEX}'/${ADA_COIN_TYPE}'/0'/2/0`,
networkId: isMainnet
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.networkId
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.networkId,
protocolMagic: isMainnet
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.protocolMagic
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.protocolMagic,
networkId: networkConfig.networkId,
protocolMagic: networkConfig.protocolMagic,
});
runInAction(
'HardwareWalletsStore:: Address show process finished',
Expand Down Expand Up @@ -1818,7 +1811,6 @@ export default class HardwareWalletsStore extends Store {
const fee = formattedAmountToLovelace(flatFee.toString());
const ttl = this._getTtl();
const absoluteSlotNumber = this._getAbsoluteSlotNumber();
const { isMainnet } = this.environment;

try {
const signedTransaction = await signTransactionTrezorChannel.request({
Expand All @@ -1827,12 +1819,8 @@ export default class HardwareWalletsStore extends Store {
fee: fee.toString(),
ttl: ttl.toString(),
validityIntervalStartStr: absoluteSlotNumber.toString(),
networkId: isMainnet
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.networkId
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.networkId,
protocolMagic: isMainnet
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.trezorProtocolMagic
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.trezorProtocolMagic,
networkId: networkConfig.networkId,
protocolMagic: networkConfig.protocolMagic,
certificates: certificatesData,
withdrawals: withdrawalsData,
devicePath: recognizedDevicePath,
Expand Down Expand Up @@ -2061,7 +2049,6 @@ export default class HardwareWalletsStore extends Store {

const fee = formattedAmountToLovelace(flatFee.toString());
const ttl = this._getTtl();
const { isMainnet } = this.environment;

let unsignedTxAuxiliaryData = null;
if (this.votingData) {
Expand Down Expand Up @@ -2089,12 +2076,8 @@ export default class HardwareWalletsStore extends Store {
fee: fee.toString(),
ttl: ttl.toString(),
validityIntervalStartStr: null,
networkId: isMainnet
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.networkId
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.networkId,
protocolMagic: isMainnet
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.protocolMagic
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.protocolMagic,
networkId: networkConfig.networkId,
protocolMagic: networkConfig.protocolMagic,
certificates: certificatesData,
withdrawals: withdrawalsData,
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
Expand Down

0 comments on commit 37524be

Please sign in to comment.