Skip to content

Commit 1628382

Browse files
[DDW-735] Hardware wallets support for all non-public Testnet magics (#2672)
* [DDW-735] Introduce an Hardware Wallets support for all non-public testnets * [DDW-735] CHANGELOG update * [DDW-735] Shelley QA network magic added to cardano-node.types and code cleanup * [DDW-735] Improve network magics declaration and HW network handlers * [DDW-735] Removing unnecessary isNonPublicTestnet flag * [DDW-735] Mark staging HW actions as mainnet like actions * [DDW-735] CHANGELOG update Co-authored-by: Nikola Glumac <[email protected]>
1 parent a093ae3 commit 1628382

File tree

8 files changed

+82
-97
lines changed

8 files changed

+82
-97
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Fixed transaction timestamps localization ([PR 2702](https://github.com/input-output-hk/daedalus/pull/2702))
88

9+
### Chores
10+
11+
- Added hardware wallet support for all non-public testnets ([PR 2672](https://github.com/input-output-hk/daedalus/pull/2672))
12+
913
## 4.4.0
1014

1115
### Features

source/common/types/cardano-node.types.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
// @flow
2+
import {
3+
MAINNET,
4+
TESTNET,
5+
STAGING,
6+
SHELLEY_QA,
7+
ALONZO_PURPLE,
8+
SELFNODE,
9+
} from './environment.types';
10+
211
export type TlsConfig = {
312
hostname: string,
413
port: number,
@@ -142,17 +151,26 @@ export type CardanoStatus = {
142151
cardanoWalletPID: number,
143152
};
144153

145-
// Cardano Mainet network magic
146-
export const MAINNET_MAGIC = [1, null];
147-
148-
// Cardano Byron Testnet network magic
149-
export const TESTNET_MAGIC = [1097911063, 0];
150-
151-
// Cardano Staging network magic
152-
export const STAGING_MAGIC = [633343913, 1];
154+
export type NetworkMagicType = Array<?number>;
153155

154-
// Cardano Alonzo Purple network magic
155-
export const ALONZO_PURPLE_MAGIC = [8, 0];
156-
157-
// Cardano Selfnode network magic
158-
export const SELFNODE_MAGIC = MAINNET_MAGIC;
156+
export const NetworkMagics: {
157+
mainnet: NetworkMagicType,
158+
testnet: NetworkMagicType,
159+
staging: NetworkMagicType,
160+
alonzo_purple: NetworkMagicType,
161+
shelley_qa: NetworkMagicType,
162+
selfnode: NetworkMagicType,
163+
} = {
164+
// Cardano Mainet network magic
165+
[MAINNET]: [1, null],
166+
// Cardano Staging network magic
167+
[STAGING]: [633343913, 1],
168+
// Cardano Byron Testnet network magic
169+
[TESTNET]: [1097911063, 0],
170+
// Cardano Alonzo Purple network magic
171+
[ALONZO_PURPLE]: [8, 0],
172+
// Cardano Shelley QA network magic
173+
[SHELLEY_QA]: [3, 0],
174+
// Cardano Selfnode network magic
175+
[SELFNODE]: [1, null],
176+
};

source/common/types/environment.types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type Environment = {
1212
isStaging: boolean,
1313
isTestnet: boolean,
1414
isAlonzoPurple: boolean,
15+
isShelleyQA: boolean,
1516
isSelfnode: boolean,
1617
isDevelopment: boolean,
1718
isWatchMode: boolean,

source/common/utils/environmentCheckers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { upperFirst } from 'lodash';
33
import {
44
ALONZO_PURPLE,
5+
SHELLEY_QA,
56
DEVELOPMENT,
67
LINUX,
78
MAC_OS,
@@ -54,6 +55,7 @@ export const checkIsMainnet = (network: string) => network === MAINNET;
5455
export const checkIsTestnet = (network: string) => network === TESTNET;
5556
export const checkIsAlonzoPurple = (network: string) =>
5657
network === ALONZO_PURPLE;
58+
export const checkIsShelleyQA = (network: string) => network === SHELLEY_QA;
5759
export const checkIsStaging = (network: string) => network === STAGING;
5860
export const checkIsSelfnode = (network: string) => network === SELFNODE;
5961
export const checkIsDevelopment = (network: string) => network === DEVELOPMENT;

source/main/environment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DEVELOPMENT, OS_NAMES } from '../common/types/environment.types';
77
import {
88
evaluateNetwork,
99
checkIsAlonzoPurple,
10+
checkIsShelleyQA,
1011
checkIsDev,
1112
checkIsTest,
1213
checkIsProduction,
@@ -34,6 +35,7 @@ const isMainnet = checkIsMainnet(NETWORK);
3435
const isStaging = checkIsStaging(NETWORK);
3536
const isTestnet = checkIsTestnet(NETWORK);
3637
const isAlonzoPurple = checkIsAlonzoPurple(NETWORK);
38+
const isShelleyQA = checkIsShelleyQA(NETWORK);
3739
const isSelfnode = checkIsSelfnode(NETWORK);
3840
const isDevelopment = checkIsDevelopment(NETWORK);
3941
const isWatchMode = process.env.IS_WATCH_MODE;
@@ -75,6 +77,7 @@ export const environment: Environment = Object.assign(
7577
isStaging,
7678
isTestnet,
7779
isAlonzoPurple,
80+
isShelleyQA,
7881
isSelfnode,
7982
isDevelopment,
8083
isWatchMode,

source/renderer/app/config/hardwareWalletsConfig.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const { isMainnet, isTestnet } = global.environment;
1+
// @flow
2+
import { get, map } from 'lodash';
3+
import { NetworkMagics } from '../../../common/types/cardano-node.types';
4+
import type { NetworkMagicType } from '../../../common/types/cardano-node.types';
5+
import type { Network } from '../../../common/types/environment.types';
26

37
export const HARDENED_HEX = 0x80000000;
48
export const HARDENED = 2147483648;
@@ -7,25 +11,18 @@ export const BYRON_PURPOSE_INDEX = 44;
711
export const ADA_COIN_TYPE = 1815;
812
export const DEFAULT_ADDRESS_INDEX = 0;
913

14+
const { isMainnet, isStaging, isSelfnode } = global.environment;
15+
const hardwareWalletNetworksConfig = {};
16+
map(NetworkMagics, (networkMagic: NetworkMagicType, network: Network) => {
17+
const isMainnetLikeNetwork = isMainnet || isSelfnode || isStaging;
18+
hardwareWalletNetworksConfig[network] = {
19+
networkId: isMainnetLikeNetwork ? 1 : networkMagic[1],
20+
protocolMagic: isMainnetLikeNetwork ? 764824073 : networkMagic[0],
21+
};
22+
});
23+
1024
export const HW_SHELLEY_CONFIG = {
11-
NETWORK: {
12-
MAINNET: {
13-
name: 'mainnet',
14-
networkId: 1,
15-
protocolMagic: 764824073,
16-
trezorProtocolMagic: 764824073,
17-
eraStartSlot: 4492800,
18-
ttl: 3600,
19-
},
20-
TESTNET: {
21-
name: 'testnet',
22-
networkId: 0,
23-
protocolMagic: 1097911063,
24-
trezorProtocolMagic: 1097911063,
25-
eraStartSlot: 4492800,
26-
ttl: 3600,
27-
},
28-
},
25+
NETWORK: hardwareWalletNetworksConfig,
2926
DEFAULT_DERIVATION_PATH: [
3027
HARDENED + SHELLEY_PURPOSE_INDEX,
3128
HARDENED + ADA_COIN_TYPE,
@@ -41,13 +38,7 @@ export const HW_SHELLEY_CONFIG = {
4138
};
4239

4340
export const HW_BYRON_CONFIG = {
44-
NETWORK: {
45-
MAINNET: {
46-
name: 'mainnet',
47-
networkId: 1,
48-
protocolMagic: 764824073,
49-
},
50-
},
41+
NETWORK: hardwareWalletNetworksConfig,
5142
DEFAULT_DERIVATION_PATH: [
5243
HARDENED + BYRON_PURPOSE_INDEX,
5344
HARDENED + ADA_COIN_TYPE,
@@ -80,6 +71,11 @@ export const isTrezorEnabled = true;
8071
export const isLedgerEnabled = true;
8172

8273
export const isHardwareWalletSupportEnabled =
83-
(isMainnet || isTestnet) && (isTrezorEnabled || isLedgerEnabled);
74+
isTrezorEnabled || isLedgerEnabled;
8475

8576
export const isHardwareWalletIndicatorEnabled = false;
77+
78+
export const getHardwareWalletsNetworkConfig = (network: Network) => {
79+
const networkConfig = get(HW_SHELLEY_CONFIG, ['NETWORK', network], {});
80+
return networkConfig;
81+
};

source/renderer/app/stores/HardwareWalletsStore.js

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { HwDeviceStatuses } from '../domains/Wallet';
1212
import WalletAddress from '../domains/WalletAddress';
1313
import { toJS } from '../../../common/utils/helper';
1414
import {
15-
HW_SHELLEY_CONFIG,
1615
SHELLEY_PURPOSE_INDEX,
1716
ADA_COIN_TYPE,
1817
MINIMAL_TREZOR_FIRMWARE_VERSION,
@@ -21,6 +20,7 @@ import {
2120
isHardwareWalletSupportEnabled,
2221
isTrezorEnabled,
2322
isLedgerEnabled,
23+
getHardwareWalletsNetworkConfig,
2424
} from '../config/hardwareWalletsConfig';
2525
import { TIME_TO_LIVE } from '../config/txnsConfig';
2626
import {
@@ -160,6 +160,9 @@ const useCardanoAppInterval = (
160160
addressVerification
161161
);
162162

163+
const { network, isDev } = global.environment;
164+
const hardwareWalletsNetworkConfig = getHardwareWalletsNetworkConfig(network);
165+
163166
export default class HardwareWalletsStore extends Store {
164167
@observable selectCoinsRequest: Request<CoinSelectionsResponse> = new Request(
165168
this.api.ada.selectCoins
@@ -262,7 +265,7 @@ export default class HardwareWalletsStore extends Store {
262265

263266
initLedger = async () => {
264267
logger.debug(
265-
`[HW-DEBUG] HWStore - initLedger() | isHardwareWalletSupportEnabled=${isHardwareWalletSupportEnabled} isLedgerEnabled=${isLedgerEnabled}`
268+
`[HW-DEBUG] HWStore - initLedger() | isHardwareWalletSupportEnabled=${isHardwareWalletSupportEnabled.toString()} isLedgerEnabled=${isLedgerEnabled.toString()}`
266269
);
267270
if (isHardwareWalletSupportEnabled && isLedgerEnabled) {
268271
logger.debug('[HW-DEBUG] HWStore - start ledger');
@@ -1131,7 +1134,6 @@ export default class HardwareWalletsStore extends Store {
11311134
}) => {
11321135
logger.debug('[HW-DEBUG] - VERIFY Address');
11331136
const { address, path, isTrezor } = params;
1134-
const { isMainnet } = this.environment;
11351137
11361138
this.hwDeviceStatus = HwDeviceStatuses.VERIFYING_ADDRESS;
11371139
this.tempAddressToVerify = params;
@@ -1142,12 +1144,8 @@ export default class HardwareWalletsStore extends Store {
11421144
addressType: AddressType.BASE,
11431145
spendingPathStr: address.spendingPath,
11441146
stakingPathStr: `${SHELLEY_PURPOSE_INDEX}'/${ADA_COIN_TYPE}'/0'/2/0`,
1145-
networkId: isMainnet
1146-
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.networkId
1147-
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.networkId,
1148-
protocolMagic: isMainnet
1149-
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.protocolMagic
1150-
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.protocolMagic,
1147+
networkId: hardwareWalletsNetworkConfig.networkId,
1148+
protocolMagic: hardwareWalletsNetworkConfig.protocolMagic,
11511149
});
11521150
11531151
if (derivedAddress === address.id) {
@@ -1239,7 +1237,6 @@ export default class HardwareWalletsStore extends Store {
12391237
}) => {
12401238
logger.debug('[HW-DEBUG] - SHOW Address');
12411239
const { address, path, isTrezor } = params;
1242-
const { isMainnet } = this.environment;
12431240
12441241
try {
12451242
await showAddressChannel.request({
@@ -1248,12 +1245,8 @@ export default class HardwareWalletsStore extends Store {
12481245
addressType: AddressType.BASE,
12491246
spendingPathStr: address.spendingPath,
12501247
stakingPathStr: `${SHELLEY_PURPOSE_INDEX}'/${ADA_COIN_TYPE}'/0'/2/0`,
1251-
networkId: isMainnet
1252-
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.networkId
1253-
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.networkId,
1254-
protocolMagic: isMainnet
1255-
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.protocolMagic
1256-
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.protocolMagic,
1248+
networkId: hardwareWalletsNetworkConfig.networkId,
1249+
protocolMagic: hardwareWalletsNetworkConfig.protocolMagic,
12571250
});
12581251
runInAction(
12591252
'HardwareWalletsStore:: Address show process finished',
@@ -1818,7 +1811,6 @@ export default class HardwareWalletsStore extends Store {
18181811
const fee = formattedAmountToLovelace(flatFee.toString());
18191812
const ttl = this._getTtl();
18201813
const absoluteSlotNumber = this._getAbsoluteSlotNumber();
1821-
const { isMainnet } = this.environment;
18221814
18231815
try {
18241816
const signedTransaction = await signTransactionTrezorChannel.request({
@@ -1827,12 +1819,8 @@ export default class HardwareWalletsStore extends Store {
18271819
fee: fee.toString(),
18281820
ttl: ttl.toString(),
18291821
validityIntervalStartStr: absoluteSlotNumber.toString(),
1830-
networkId: isMainnet
1831-
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.networkId
1832-
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.networkId,
1833-
protocolMagic: isMainnet
1834-
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.trezorProtocolMagic
1835-
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.trezorProtocolMagic,
1822+
networkId: hardwareWalletsNetworkConfig.networkId,
1823+
protocolMagic: hardwareWalletsNetworkConfig.protocolMagic,
18361824
certificates: certificatesData,
18371825
withdrawals: withdrawalsData,
18381826
devicePath: recognizedDevicePath,
@@ -2061,7 +2049,6 @@ export default class HardwareWalletsStore extends Store {
20612049

20622050
const fee = formattedAmountToLovelace(flatFee.toString());
20632051
const ttl = this._getTtl();
2064-
const { isMainnet } = this.environment;
20652052

20662053
let unsignedTxAuxiliaryData = null;
20672054
if (this.votingData) {
@@ -2089,12 +2076,8 @@ export default class HardwareWalletsStore extends Store {
20892076
fee: fee.toString(),
20902077
ttl: ttl.toString(),
20912078
validityIntervalStartStr: null,
2092-
networkId: isMainnet
2093-
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.networkId
2094-
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.networkId,
2095-
protocolMagic: isMainnet
2096-
? HW_SHELLEY_CONFIG.NETWORK.MAINNET.protocolMagic
2097-
: HW_SHELLEY_CONFIG.NETWORK.TESTNET.protocolMagic,
2079+
networkId: hardwareWalletsNetworkConfig.networkId,
2080+
protocolMagic: hardwareWalletsNetworkConfig.protocolMagic,
20982081
certificates: certificatesData,
20992082
withdrawals: withdrawalsData,
21002083
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
@@ -2715,7 +2698,7 @@ export default class HardwareWalletsStore extends Store {
27152698

27162699
// For testing / development ONLY
27172700
_resetHardwareWallets = async () => {
2718-
if (global.environment.isDev) {
2701+
if (isDev) {
27192702
await Promise.all(
27202703
this.stores.wallets.all.map(async (wallet) => {
27212704
if (wallet.isHardwareWallet) {

source/renderer/app/stores/WalletsStore.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ import {
3333
import { IS_WALLET_PUBLIC_KEY_SHARING_ENABLED } from '../config/walletsConfig';
3434
import { introspectAddressChannel } from '../ipc/introspect-address';
3535
import { saveQRCodeImageChannel } from '../ipc/saveQRCodeImageChannel';
36-
import {
37-
TESTNET_MAGIC,
38-
SELFNODE_MAGIC,
39-
STAGING_MAGIC,
40-
MAINNET_MAGIC,
41-
ALONZO_PURPLE_MAGIC,
42-
} from '../../../common/types/cardano-node.types';
4336
import type { AddressStyle } from '../../../common/types/address-introspection.types';
4437
import type { AssetToken } from '../api/assets/types';
4538
import type {
@@ -61,6 +54,7 @@ import type {
6154
TransportDevice,
6255
HardwareWalletExtendedPublicKeyResponse,
6356
} from '../../../common/types/hardware-wallets.types';
57+
import { NetworkMagics } from '../../../common/types/cardano-node.types';
6458

6559
/* eslint-disable consistent-return */
6660

@@ -1029,28 +1023,12 @@ export default class WalletsStore extends Store {
10291023
};
10301024

10311025
isValidAddress = async (address: string) => {
1032-
const {
1033-
isMainnet,
1034-
isSelfnode,
1035-
isStaging,
1036-
isTestnet,
1037-
isAlonzoPurple,
1038-
} = this.environment;
1039-
let expectedNetworkTag: ?Array<?number> | ?number;
1026+
const { network } = this.environment;
1027+
const expectedNetworkTag = get(NetworkMagics, [network]);
10401028
const validAddressStyles: AddressStyle[] = ['Byron', 'Icarus', 'Shelley'];
10411029
this.isAddressFromSameWallet = false;
10421030

1043-
if (isMainnet) {
1044-
expectedNetworkTag = MAINNET_MAGIC;
1045-
} else if (isStaging) {
1046-
expectedNetworkTag = STAGING_MAGIC;
1047-
} else if (isTestnet) {
1048-
expectedNetworkTag = TESTNET_MAGIC;
1049-
} else if (isAlonzoPurple) {
1050-
expectedNetworkTag = ALONZO_PURPLE_MAGIC;
1051-
} else if (isSelfnode) {
1052-
expectedNetworkTag = SELFNODE_MAGIC;
1053-
} else {
1031+
if (!expectedNetworkTag) {
10541032
throw new Error('Unexpected environment');
10551033
}
10561034
try {

0 commit comments

Comments
 (0)