From 350d71521efcb3f567e45e71b9ae9f42e0db6dbd Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Thu, 20 Dec 2018 19:30:00 +0100 Subject: [PATCH] validate via wallet-address-validator lib --- package.json | 1 + src/actions/ripple/SendFormValidationActions.js | 4 ++-- yarn.lock | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0fa8d1f5..f5387414 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "styled-components": "^4.1.2", "styled-normalize": "^8.0.4", "trezor-connect": "6.0.3-beta.5", + "wallet-address-validator": "^0.2.4", "web3": "1.0.0-beta.35", "webpack": "^4.16.3", "webpack-build-notifier": "^0.1.29", diff --git a/src/actions/ripple/SendFormValidationActions.js b/src/actions/ripple/SendFormValidationActions.js index c573997a..9c5f1b01 100644 --- a/src/actions/ripple/SendFormValidationActions.js +++ b/src/actions/ripple/SendFormValidationActions.js @@ -12,8 +12,8 @@ import type { } from 'flowtype'; import type { State, FeeLevel } from 'reducers/SendFormRippleReducer'; +import AddressValidator from 'wallet-address-validator'; // general regular expressions -const XRP_ADDRESS_RE = new RegExp('^r[1-9A-HJ-NP-Za-km-z]{25,34}$'); const NUMBER_RE: RegExp = new RegExp('^(0|0\\.([0-9]+)?|[1-9][0-9]*\\.?([0-9]+)?|\\.[0-9]+)$'); const XRP_6_RE = new RegExp('^(0|0\\.([0-9]{0,6})?|[1-9][0-9]*\\.?([0-9]{0,6})?|\\.[0-9]{0,6})$'); @@ -113,7 +113,7 @@ const addressValidation = ($state: State): PayloadAction => (dispatch: Di if (address.length < 1) { state.errors.address = 'Address is not set'; - } else if (!address.match(XRP_ADDRESS_RE)) { + } else if (!AddressValidator.validate(address, 'XRP')) { state.errors.address = 'Address is not valid'; } else if (address.toLowerCase() === account.address.toLowerCase()) { state.errors.address = 'Cannot send to myself'; diff --git a/yarn.lock b/yarn.lock index f26975ff..bd1dec40 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1707,6 +1707,12 @@ balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" +base-x@^3.0.4: + version "3.0.5" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.5.tgz#d3ada59afed05b921ab581ec3112e6444ba0795a" + dependencies: + safe-buffer "^5.0.1" + base16@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/base16/-/base16-1.0.0.tgz#e297f60d7ec1014a7a971a39ebc8a98c0b681e70" @@ -6021,6 +6027,10 @@ jsprim@^1.2.2: json-schema "0.2.3" verror "1.10.0" +jssha@2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/jssha/-/jssha-2.3.1.tgz#147b2125369035ca4b2f7d210dc539f009b3de9a" + jsx-ast-utils@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz#e801b1b39985e20fffc87b40e3748080e2dcac7f" @@ -10281,6 +10291,13 @@ walker@~1.0.5: dependencies: makeerror "1.0.x" +wallet-address-validator@^0.2.4: + version "0.2.4" + resolved "https://registry.yarnpkg.com/wallet-address-validator/-/wallet-address-validator-0.2.4.tgz#717ce316143b679645639986cc0847a107255881" + dependencies: + base-x "^3.0.4" + jssha "2.3.1" + warning@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"