HomePhabricator

[Cashtab] Refactor address validation to accept prefixless addresses

Description

[Cashtab] Refactor address validation to accept prefixless addresses

Summary:
T1868

Cashtab address validation has developed incrementally based on shifting demands for address format types, including bitcoincash: format, simpleledger: format, both these legacy formats and the new ecash: + etoken: standard, and only the new standard. Some exchanges have begun using valid ecash: and etoken: addresses without prefixes, so Cashtab should support these too.

Another lingering complication is that the backend only accepts addresses in bitcoincash: or simpleledger: format. So, Cashtab must preserve methods for converting to these formats (even while it does not recognize them as valid user input).

A diff was submitted (D10158) to accomplish this -- but did so by adding another layer of technical debt. At this point, the address validation should be refactored to support ecash formats.

This diff introduces new simplified methods for validating addresses input by the user.

isValidXecAddress - Accepts a valid ecash address with or without the ecash: prefix (checksum must match ecash: prefix
isValidEtokenAddress Accepts a valid etoken address with or without the etoken: prefix (checksum must match etoken: prefix
toLegacyCash - Accepts a valid ecash: address and returns a valid bitcoincash: address
toLegacyToken - Accepts a valid etoken: address and returns a valid simpleledger: address

Validation for send to many was also updated to support these new methods. Previous validation was complicated by the existence of address validation in the parseAddress function. This function has been refactored and simplified.

Some functions were moved from Ticker.js into cashMethods.js as part of this refactor because they are related to each other.

A future diff will remove the now-obsolete isValidCashPrefix and isValidTokenPrefix functions from Ticker.js and ScanQRCode.js. Another future diff will move other functions from Ticker.js that belong in cashMethods.js

Test Plan:
npm start

  1. Navigate to Send screen
  2. Enter a valid ecash address with prefix. Confirm no error
  3. Delete the prefix. Confirm no error.
  4. Enter a valid bitcoincash address with prefix. Confirm error.
  5. Enter a valid bitcoincash address without prefix. Confirm error.
  6. Enter a valid legacy BTC address. Confirm error.
  7. Enter a random string. Confirm error.
  8. Perform same tests with amounts in "multi send"
  9. Navigate to Send Token page. Perform steps 2-7 with simpleledger address instead of bitcoincash address.

Reviewers: #bitcoin_abc, emack

Reviewed By: #bitcoin_abc, emack

Subscribers: emack

Differential Revision: https://reviews.bitcoinabc.org/D10687

Details

Provenance
Joey King <joseph.roy.king@gmail.com>Authored on Dec 15 2021, 19:12
bytesofmanPushed on Dec 22 2021, 18:11
Reviewer
Restricted Project
Differential Revision
D10687: [Cashtab] Refactor address validation to accept prefixless addresses
Parents
rABC2228b24e18a6: tests: increase timeout in getnettotals test
Branches
Unknown
Tags
Unknown