2018-03-21 00:35:34 +00:00
|
|
|
function destinationsToAmount(destinations){
|
|
|
|
// Gets amount from destinations line
|
|
|
|
// input: "20.000000000000: 9tLGyK277MnYrDc7Vzi6TB1pJvstFoviziFwsqQNFbwA9rvg5RxYVYjEezFKDjvDHgAzTELJhJHVx6JAaWZKeVqSUZkXeKk"
|
|
|
|
// returns: 20.000000000000
|
|
|
|
return destinations.split(" ")[0].split(":")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function destinationsToAddress(destinations){
|
|
|
|
var address = destinations.split(" ")[1];
|
|
|
|
if(address === undefined) return ""
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
2018-04-27 22:50:33 +00:00
|
|
|
function addressTruncate(address, range){
|
2019-07-01 21:19:29 +00:00
|
|
|
if(typeof(address) === "undefined") return "";
|
2018-04-27 22:50:33 +00:00
|
|
|
if(typeof(range) === "undefined") range = 8;
|
|
|
|
return address.substring(0, range) + "..." + address.substring(address.length-range);
|
2018-03-21 00:35:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 16:49:37 +00:00
|
|
|
function addressTruncatePretty(address, blocks){
|
2019-07-01 21:19:29 +00:00
|
|
|
if(typeof(address) === "undefined") return "";
|
2019-04-05 16:49:37 +00:00
|
|
|
if(typeof(blocks) === "undefined") blocks = 2;
|
2019-04-16 09:09:46 +00:00
|
|
|
blocks = blocks <= 1 ? 1 : blocks >= 23 ? 23 : blocks;
|
2019-04-05 16:49:37 +00:00
|
|
|
var ret = "";
|
|
|
|
return address.substring(0, 4 * blocks).match(/.{1,4}/g).join(' ') + " .. " + address.substring(address.length - 4 * blocks).match(/.{1,4}/g).join(' ');
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:35:34 +00:00
|
|
|
function check256(str, length) {
|
|
|
|
if (str.length != length)
|
|
|
|
return false;
|
|
|
|
for (var i = 0; i < length; ++i) {
|
|
|
|
if (str[i] >= '0' && str[i] <= '9')
|
|
|
|
continue;
|
|
|
|
if (str[i] >= 'a' && str[i] <= 'z')
|
|
|
|
continue;
|
|
|
|
if (str[i] >= 'A' && str[i] <= 'Z')
|
|
|
|
continue;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAddress(address, testnet) {
|
|
|
|
return walletManager.addressValid(address, testnet)
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkTxID(txid) {
|
|
|
|
return check256(txid, 64)
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkSignature(signature) {
|
|
|
|
if (signature.indexOf("OutProofV") === 0) {
|
|
|
|
if ((signature.length - 10) % 132 != 0)
|
|
|
|
return false;
|
|
|
|
return check256(signature, signature.length);
|
|
|
|
} else if (signature.indexOf("InProofV") === 0) {
|
|
|
|
if ((signature.length - 9) % 132 != 0)
|
|
|
|
return false;
|
|
|
|
return check256(signature, signature.length);
|
|
|
|
} else if (signature.indexOf("SpendProofV") === 0) {
|
|
|
|
if ((signature.length - 12) % 88 != 0)
|
|
|
|
return false;
|
|
|
|
return check256(signature, signature.length);
|
2022-01-18 21:10:56 +00:00
|
|
|
} else if (signature.indexOf("ReserveProofV") === 0) {
|
|
|
|
if ((signature.length - 14) % 447 != 0)
|
|
|
|
return false;
|
|
|
|
return check256(signature, signature.length);
|
2018-03-21 00:35:34 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-19 21:37:52 +00:00
|
|
|
function isValidOpenAliasAddress(address) {
|
2023-11-13 01:27:15 +00:00
|
|
|
var regex = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/; // Basic domain structure
|
|
|
|
|
|
|
|
if (!regex.test(address)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const lastPart = address.substring(address.lastIndexOf('.') + 1);
|
|
|
|
return isNaN(parseInt(lastPart)) || lastPart !== parseInt(lastPart).toString();
|
2018-12-19 21:37:52 +00:00
|
|
|
}
|
2023-04-21 12:45:09 +00:00
|
|
|
|
|
|
|
function handleOpenAliasResolution(address, descriptionText) {
|
|
|
|
const result = walletManager.resolveOpenAlias(address);
|
|
|
|
if (!result) {
|
|
|
|
return { message: qsTr("No address found") };
|
|
|
|
}
|
|
|
|
|
|
|
|
const [isDnssecValid, resolvedAddress] = result.split("|");
|
|
|
|
const isAddressValid = walletManager.addressValid(resolvedAddress, appWindow.persistentSettings.nettype);
|
|
|
|
let updatedDescriptionText = descriptionText;
|
|
|
|
|
|
|
|
if (isDnssecValid === "true") {
|
|
|
|
if (isAddressValid) {
|
|
|
|
updatedDescriptionText = descriptionText ? `${address} ${descriptionText}` : address;
|
|
|
|
return { address: resolvedAddress, description: updatedDescriptionText };
|
|
|
|
} else {
|
|
|
|
return { message: qsTr("No valid address found at this OpenAlias address") };
|
|
|
|
}
|
|
|
|
} else if (isDnssecValid === "false") {
|
|
|
|
if (isAddressValid) {
|
|
|
|
return {
|
|
|
|
address: resolvedAddress,
|
|
|
|
message: qsTr("Address found, but the DNSSEC signatures could not be verified, so this address may be spoofed"),
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return { message: qsTr("No valid address found at this OpenAlias address, but the DNSSEC signatures could not be verified, so this may be spoofed") };
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return { message: qsTr("Internal error") };
|
|
|
|
}
|
|
|
|
}
|