Function attemptCashAddressFormatErrorCorrection

  • Attempt to correct up to 2 errors in a CashAddress-formatted string. The string must include the prefix and only contain Bech32 characters.

    CAUTION: improper use of this function can lead to lost funds.

    Using error correction of CashAddress-like formats degrades error detection, i.e. if the payload contains more than 2 errors, it is possible that error correction will "correct" the payload to a plausible but incorrect payload.

    For applications which proceed to take irreversible actions – like sending a payment – naive usage of CashAddress Format error correction can lead to vulnerabilities and lost funds.

    It is strongly advised that this method only be used in fail-safe applications (e.g. automatic correction of CashAddress-formatted private key material during wallet recovery) or under explicit user control (e.g. "The address you entered is invalid, please review the highlighted characters and try again.").

    Only 2 substitution errors can be corrected (or a single swap) – deletions and insertions (errors that shift many other characters and change the length of the payload) can never be safely corrected and will produce an error.

    Errors can be corrected in both the prefix and the payload, but attempting to correct errors in the prefix prior to this method can improve results, e.g. for bchtest:qq2azmyyv6dtgczexyalqar70q036yund53jvfde0x, the string bchtest:qq2azmyyv6dtgczexyalqar70q036yund53jvfdecc can be corrected, while typo:qq2azmyyv6dtgczexyalqar70q036yund53jvfdecc can not.


    • address: string

      The address or formatted data to correct.

    Returns string | CashAddressFormatCorrection

Generated using TypeDoc