Skip to content

Commit 98c6fd4

Browse files
[DDW-742] Fix receiver address validation (disallow rewards address) (#2781)
1 parent 0954d1a commit 98c6fd4

File tree

7 files changed

+43
-24
lines changed

7 files changed

+43
-24
lines changed

CHANGELOG.md

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

33
## vNext
44

5+
### Fixes
6+
7+
- Fixed receiver address validation by disallowing rewards addresses ([PR 2781](https://github.com/input-output-hk/daedalus/pull/2781))
8+
59
### Chores
610

711
- Updated vulnerable dependencies ([PR 2769](https://github.com/input-output-hk/daedalus/pull/2769))

nix/sources.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"homepage": null,
3030
"owner": "input-output-hk",
3131
"repo": "cardano-wallet",
32-
"rev": "dac16ba7e3bf64bf5474497656932fd342c3b720",
33-
"sha256": "012lnp5rah4qyl8r0v04d0rz28b1rdaz6flhjrahf45b9gx7mny1",
32+
"rev": "760140e238a5fbca61d1b286d7a80ece058dc729",
33+
"sha256": "014njpddrlqm9bbab636h2gf58zkm0bx04i1jsn07vh5j3k0gri6",
3434
"type": "tarball",
35-
"url": "https://github.com/input-output-hk/cardano-wallet/archive/dac16ba7e3bf64bf5474497656932fd342c3b720.tar.gz",
35+
"url": "https://github.com/input-output-hk/cardano-wallet/archive/760140e238a5fbca61d1b286d7a80ece058dc729.tar.gz",
3636
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
3737
},
3838
"gitignore": {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@
134134
"husky": "4.3.0",
135135
"identity-obj-proxy": "3.0.0",
136136
"jest": "26.6.3",
137-
"jest-css-modules-transform": "^4.3.0",
137+
"jest-css-modules-transform": "4.3.0",
138138
"jest-environment-jsdom": "26.6.2",
139-
"jest-svg-transformer": "^1.0.0",
139+
"jest-svg-transformer": "1.0.0",
140140
"markdown-loader": "5.1.0",
141141
"mini-css-extract-plugin": "0.12.0",
142142
"minimist": "1.2.5",

source/common/types/address-introspection.types.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export type IntrospectAddressRequest = {
44
input: string,
55
};
66

7-
export type AddressStyle = 'Byron' | 'Icarus' | 'Jormungandr' | 'Shelley';
7+
export type AddressStyle = 'Byron' | 'Icarus' | 'Shelley';
8+
9+
export type AddressType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15;
810

911
export type ChainPointer = {
1012
slot_num: number,
@@ -13,6 +15,7 @@ export type ChainPointer = {
1315
};
1416

1517
export type AddressBase = {
18+
address_type: AddressType,
1619
address_style: AddressStyle,
1720
network_tag: number | null,
1821
stake_reference: 'none' | 'by pointer' | 'by value',
@@ -27,14 +30,6 @@ export type IcarusAddress = AddressBase & {
2730
address_root: string,
2831
};
2932

30-
export type JormungandrAddress = AddressBase & {
31-
address_type: 'single' | 'group' | 'account' | 'multisig',
32-
account_key?: string,
33-
merkle_root?: string,
34-
spending_key?: string,
35-
stake_key?: string,
36-
};
37-
3833
export type ShelleyAddress = AddressBase & {
3934
pointer?: ChainPointer,
4035
script_hash?: string,
@@ -45,10 +40,6 @@ export type ShelleyAddress = AddressBase & {
4540

4641
export type IntrospectAddressResponse =
4742
| {
48-
introspection:
49-
| ByronAddress
50-
| IcarusAddress
51-
| JormungandrAddress
52-
| ShelleyAddress,
43+
introspection: ByronAddress | IcarusAddress | ShelleyAddress,
5344
}
5445
| 'Invalid';

source/renderer/app/stores/WalletsStore.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import { logger } from '../utils/logging';
1818
import { ROUTES } from '../routes-config';
1919
import { formattedWalletAmount } from '../utils/formatters';
2020
import { ellipsis } from '../utils/strings';
21-
import { bech32EncodePublicKey } from '../utils/hardwareWalletUtils';
21+
import {
22+
bech32EncodePublicKey,
23+
isReceiverAddressType,
24+
} from '../utils/hardwareWalletUtils';
2225
import {
2326
WalletPaperWalletOpenPdfError,
2427
WalletRewardsOpenCsvError,
@@ -1039,9 +1042,14 @@ export default class WalletsStore extends Store {
10391042
}
10401043
try {
10411044
const response = await introspectAddressChannel.send({ input: address });
1042-
if (response === 'Invalid') {
1045+
1046+
if (
1047+
response === 'Invalid' ||
1048+
!isReceiverAddressType(response.introspection.address_type)
1049+
) {
10431050
return false;
10441051
}
1052+
10451053
runInAction('check if address is from the same wallet', () => {
10461054
const walletAddresses = this.stores.addresses.all
10471055
.slice()

source/renderer/app/utils/hardwareWalletUtils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { HARDENED } from '../config/hardwareWalletsConfig';
66

77
// Types
88
import type { CoinSelectionAssetsType } from '../api/transactions/types';
9+
import type { AddressType } from '../../../common/types/address-introspection.types';
910

1011
export type PathRoleIdentityType =
1112
| 'utxo_external'
@@ -38,6 +39,21 @@ export const KEY_PREFIXES = {
3839

3940
// Helpers
4041

42+
const receiverAddressTypes: Set<AddressType> = new Set([
43+
0,
44+
1,
45+
2,
46+
3,
47+
4,
48+
5,
49+
6,
50+
7,
51+
8,
52+
]);
53+
54+
export const isReceiverAddressType = (addressType: AddressType) =>
55+
receiverAddressTypes.has(addressType);
56+
4157
// [1852H, 1815H, 0H] => m/1852'/1815'/0'
4258
export const derivationPathToString = (derivationPath: Array<string>) => {
4359
let constructedPath = 'm';

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@
28492849
version "1.0.0"
28502850
resolved "https://registry.yarnpkg.com/@types/is-function/-/is-function-1.0.0.tgz#1b0b819b1636c7baf0d6785d030d12edf70c3e83"
28512851

2852-
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
2852+
"@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
28532853
version "2.0.3"
28542854
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"
28552855

@@ -10756,7 +10756,7 @@ jest-config@^26.6.3:
1075610756
micromatch "^4.0.2"
1075710757
pretty-format "^26.6.2"
1075810758

10759-
jest-css-modules-transform@^4.3.0:
10759+
jest-css-modules-transform@4.3.0:
1076010760
version "4.3.0"
1076110761
resolved "https://registry.yarnpkg.com/jest-css-modules-transform/-/jest-css-modules-transform-4.3.0.tgz#e3599b6b9326230f9c127953aca99f91d9286ab1"
1076210762
dependencies:
@@ -11153,7 +11153,7 @@ jest-snapshot@^26.6.2:
1115311153
pretty-format "^26.6.2"
1115411154
semver "^7.3.2"
1115511155

11156-
jest-svg-transformer@^1.0.0:
11156+
jest-svg-transformer@1.0.0:
1115711157
version "1.0.0"
1115811158
resolved "https://registry.yarnpkg.com/jest-svg-transformer/-/jest-svg-transformer-1.0.0.tgz#e38884ca4cd8b2295cdfa2a0b24667920c3a8a6d"
1115911159

0 commit comments

Comments
 (0)