"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.XrpAddress = exports.R_B58_DICT = void 0;
const AddressBase_1 = require("../AddressBase");
const crypto = __importStar(require("crypto"));
const base_x_1 = __importDefault(require("base-x"));
const algoUtils_1 = require("../../utils/algoUtils");
const utils_1 = require("../../utils/utils");
exports.R_B58_DICT = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
const base58 = (0, base_x_1.default)(exports.R_B58_DICT);
const classicAddressRegex = /r[rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz]{27,35}/;
class XrpAddress extends AddressBase_1.AddressBase {
    get type() {
        if (this.isValidClassicAddressFormat()) {
            return "classic";
        }
        else {
            return "invalid";
        }
    }
    get stdHash() {
        const dec = (0, utils_1.prefix0x)((0, algoUtils_1.bytesToHex)((0, utils_1.xrpBase58Decode)(this.privateData)));
        return XrpAddress.toStandardHash(dec);
    }
    isChecksumValid() {
        const dec = base58.decode(this.privateData);
        const c1 = crypto.createHash("sha256").update(dec.slice(0, -4)).digest();
        const c2 = crypto.createHash("sha256").update(c1).digest();
        const checksum_computed = c2.slice(0, 4);
        const checksum_read = dec.slice(-4);
        return checksum_computed.equals(checksum_read);
    }
    isValid() {
        return this.isValidClassicAddressFormat() && this.isChecksumValid() && base58.decode(this.privateData).length == 25;
    }
    get isMainnet() {
        if (this.isValid() && this.privateData[0] == "r")
            return true;
        else
            return false;
    }
    isValidClassicAddressFormat() {
        return classicAddressRegex.test(this.privateData);
    }
}
exports.XrpAddress = XrpAddress;
//# sourceMappingURL=XrpAddress.js.map