"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DogeAddress = void 0;
const utils_1 = require("../../utils/utils");
const AddressBase_1 = require("../AddressBase");
const AddressTypes_1 = require("./AddressTypes");
const UtxoAddress_1 = require("./UtxoAddress");
class DogeAddress extends UtxoAddress_1.UtxoAddress {
    get prefix() {
        return this.privateData[0];
    }
    get type() {
        switch (this.prefix) {
            case "D":
                return AddressTypes_1.UtxoAddressTypes.P2PKH;
            case "n":
                return AddressTypes_1.UtxoAddressTypes.TEST_P2PKH;
            case "m":
                return AddressTypes_1.UtxoAddressTypes.TEST_P2PKH;
            case "2":
                return AddressTypes_1.UtxoAddressTypes.TEST_P2SH;
            case "A":
            case "9":
                return AddressTypes_1.UtxoAddressTypes.P2SH;
            default:
                return AddressTypes_1.UtxoAddressTypes.INVALID;
        }
    }
    get stdHash() {
        if (!this.isValid())
            throw new Error("invalid address");
        switch (this.type) {
            case AddressTypes_1.UtxoAddressTypes.P2PKH:
            case AddressTypes_1.UtxoAddressTypes.P2SH:
            case AddressTypes_1.UtxoAddressTypes.TEST_P2PKH:
            case AddressTypes_1.UtxoAddressTypes.TEST_P2SH:
                return AddressBase_1.AddressBase.toStandardHash((0, utils_1.prefix0x)((0, utils_1.btcBase58Decode)(this.privateData).toString("hex")));
            default:
                throw new Error("invalid address");
        }
    }
    isValid() {
        switch (this.type) {
            case AddressTypes_1.UtxoAddressTypes.P2PKH:
            case AddressTypes_1.UtxoAddressTypes.P2SH:
            case AddressTypes_1.UtxoAddressTypes.TEST_P2PKH:
            case AddressTypes_1.UtxoAddressTypes.TEST_P2SH:
                //invalid length
                if (25 > this.privateData.length || this.privateData.length > 34) {
                    return false;
                }
                if (utils_1.BTC_BASE_58_DICT_regex.test(this.privateData))
                    return false; // contains invalid characters
                return (0, utils_1.btcBase58Checksum)(this.privateData);
            default:
                return false;
        }
    }
    addressToPkscript() {
        if (!this.isValid())
            throw new Error("invalid address");
        switch (this.type) {
            case AddressTypes_1.UtxoAddressTypes.P2PKH:
            case AddressTypes_1.UtxoAddressTypes.P2SH:
            case AddressTypes_1.UtxoAddressTypes.TEST_P2PKH:
            case AddressTypes_1.UtxoAddressTypes.TEST_P2SH:
                return (0, utils_1.dogeBase58AddrToPkScript)(this.privateData);
            default:
                throw new Error("invalid address");
        }
    }
}
exports.DogeAddress = DogeAddress;
//# sourceMappingURL=DogeAddress.js.map