status-desktop/ui/imports/Utils.qml

43 lines
1.2 KiB
QML
Raw Normal View History

pragma Singleton
import QtQuick 2.13
QtObject {
function isHex(value) {
return /^(-0x|0x)?[0-9a-f]*$/i.test(value)
}
function startsWith0x(value) {
return value.startsWith('0x')
}
function isChatKey(value) {
return startsWith0x(value) && isHex(value) && value.length === 132
}
2020-06-25 13:26:58 +00:00
function isValidETHNamePrefix(value) {
return !(value.trim() === "" || value.endsWith(".") || value.indexOf("..") > -1)
}
function isAddress(value) {
return startsWith0x(value) && isHex(value) && value.length === 42
}
function isPrivateKey(value) {
return isHex(value) && ((startsWith0x(value) && value.length === 66) ||
(!startsWith0x(value) && value.length === 64))
}
2020-06-22 17:57:06 +00:00
function isMnemonic(value) {
// Do we support other length than 12?
return value.split(/\s|,/).length === 12
}
2020-06-25 13:26:58 +00:00
function compactAddress(addr, numberOfChars) {
if(addr.length <= 5 + (numberOfChars * 2)){ // 5 represents these chars 0x...
return addr;
}
return addr.substring(0, 2 + numberOfChars) + "..." + addr.substring(addr.length - numberOfChars);
}
}