0d6e143398
Build All Platforms / test-linux-unit (push) Failing after 40s
Build All Platforms / build-linux-qt (push) Failing after 40s
Build All Platforms / build-linux-daemon (push) Failing after 40s
Build All Platforms / build-windows-qt (push) Has been cancelled
Build All Platforms / build-windows-daemon (push) Has been cancelled
Build All Platforms / build-macos (push) Has been cancelled
Build All Platforms / release (push) Has been cancelled
Build All Platforms / Trigger TRI-PI ARM64 Build (push) Has been cancelled
- Address validator accepts V3 .onion format (62 chars, base32 + .onion) - WalletModel::validateAddress() recognizes .onion via ValidateOnionAddress() - Send coins/messages dialogs resolve .onion to TRI before sending - Auto-request getwalletaddr from onion peers after version handshake - Placeholder text updated to "Enter a TRI address or .onion address" - Shows info dialog if resolution is pending (async connect + resolve) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
94 lines
2.4 KiB
C++
94 lines
2.4 KiB
C++
#include "trianglesaddressvalidator.h"
|
|
|
|
/* Base58 characters are:
|
|
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
|
|
This is:
|
|
- All numbers except for '0'
|
|
- All upper-case letters except for 'I' and 'O'
|
|
- All lower-case letters except for 'l'
|
|
|
|
User friendly Base58 input can map
|
|
- 'l' and 'I' to '1'
|
|
- '0' and 'O' to 'o'
|
|
*/
|
|
|
|
TrianglesAddressValidator::TrianglesAddressValidator(QObject *parent) :
|
|
QValidator(parent)
|
|
{
|
|
}
|
|
|
|
QValidator::State TrianglesAddressValidator::validate(QString &input, int &pos) const
|
|
{
|
|
// Correction
|
|
for(int idx=0; idx<input.size();)
|
|
{
|
|
bool removeChar = false;
|
|
QChar ch = input.at(idx);
|
|
// Corrections made are very conservative on purpose, to avoid
|
|
// users unexpectedly getting away with typos that would normally
|
|
// be detected, and thus sending to the wrong address.
|
|
switch(ch.unicode())
|
|
{
|
|
// Qt categorizes these as "Other_Format" not "Separator_Space"
|
|
case 0x200B: // ZERO WIDTH SPACE
|
|
case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
|
|
removeChar = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
// Remove whitespace
|
|
if(ch.isSpace())
|
|
removeChar = true;
|
|
// To next character
|
|
if(removeChar)
|
|
input.remove(idx, 1);
|
|
else
|
|
++idx;
|
|
}
|
|
|
|
// Validation
|
|
QValidator::State state = QValidator::Acceptable;
|
|
|
|
// Allow .onion addresses (base32 lowercase + digits 2-7 + period)
|
|
bool isOnion = input.endsWith(".onion");
|
|
|
|
for(int idx=0; idx<input.size(); ++idx)
|
|
{
|
|
int ch = input.at(idx).unicode();
|
|
|
|
if (isOnion)
|
|
{
|
|
// V3 onion: base32 (a-z, 2-7) + ".onion" suffix
|
|
if ((ch >= 'a' && ch <= 'z') || (ch >= '2' && ch <= '7') || ch == '.')
|
|
{
|
|
// Valid onion character
|
|
}
|
|
else
|
|
{
|
|
state = QValidator::Invalid;
|
|
}
|
|
}
|
|
else if(((ch >= '0' && ch<='9') ||
|
|
(ch >= 'a' && ch<='z') ||
|
|
(ch >= 'A' && ch<='Z')) &&
|
|
ch != 'l' && ch != 'I' && ch != '0' && ch != 'O')
|
|
{
|
|
// Alphanumeric and not a 'forbidden' character
|
|
}
|
|
else
|
|
{
|
|
state = QValidator::Invalid;
|
|
}
|
|
}
|
|
|
|
// Empty address is "intermediate" input
|
|
if(input.isEmpty())
|
|
{
|
|
state = QValidator::Intermediate;
|
|
}
|
|
|
|
return state;
|
|
}
|