"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    CAIP_CHAIN_ID_REGEX: function() {
        return CAIP_CHAIN_ID_REGEX;
    },
    CAIP_NAMESPACE_REGEX: function() {
        return CAIP_NAMESPACE_REGEX;
    },
    CAIP_REFERENCE_REGEX: function() {
        return CAIP_REFERENCE_REGEX;
    },
    CAIP_ACCOUNT_ID_REGEX: function() {
        return CAIP_ACCOUNT_ID_REGEX;
    },
    CAIP_ACCOUNT_ADDRESS_REGEX: function() {
        return CAIP_ACCOUNT_ADDRESS_REGEX;
    },
    CaipChainIdStruct: function() {
        return CaipChainIdStruct;
    },
    CaipNamespaceStruct: function() {
        return CaipNamespaceStruct;
    },
    CaipReferenceStruct: function() {
        return CaipReferenceStruct;
    },
    CaipAccountIdStruct: function() {
        return CaipAccountIdStruct;
    },
    CaipAccountAddressStruct: function() {
        return CaipAccountAddressStruct;
    },
    isCaipChainId: function() {
        return isCaipChainId;
    },
    isCaipNamespace: function() {
        return isCaipNamespace;
    },
    isCaipReference: function() {
        return isCaipReference;
    },
    isCaipAccountId: function() {
        return isCaipAccountId;
    },
    isCaipAccountAddress: function() {
        return isCaipAccountAddress;
    },
    parseCaipChainId: function() {
        return parseCaipChainId;
    },
    parseCaipAccountId: function() {
        return parseCaipAccountId;
    }
});
const _superstruct = require("superstruct");
const CAIP_CHAIN_ID_REGEX = RegExp("^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$", "u");
const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;
const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;
const CAIP_ACCOUNT_ID_REGEX = RegExp("^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$", "u");
const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;
const CaipChainIdStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), CAIP_CHAIN_ID_REGEX);
const CaipNamespaceStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), CAIP_NAMESPACE_REGEX);
const CaipReferenceStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), CAIP_REFERENCE_REGEX);
const CaipAccountIdStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), CAIP_ACCOUNT_ID_REGEX);
const CaipAccountAddressStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), CAIP_ACCOUNT_ADDRESS_REGEX);
function isCaipChainId(value) {
    return (0, _superstruct.is)(value, CaipChainIdStruct);
}
function isCaipNamespace(value) {
    return (0, _superstruct.is)(value, CaipNamespaceStruct);
}
function isCaipReference(value) {
    return (0, _superstruct.is)(value, CaipReferenceStruct);
}
function isCaipAccountId(value) {
    return (0, _superstruct.is)(value, CaipAccountIdStruct);
}
function isCaipAccountAddress(value) {
    return (0, _superstruct.is)(value, CaipAccountAddressStruct);
}
function parseCaipChainId(caipChainId) {
    const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);
    if (!match?.groups) {
        throw new Error('Invalid CAIP chain ID.');
    }
    return {
        namespace: match.groups.namespace,
        reference: match.groups.reference
    };
}
function parseCaipAccountId(caipAccountId) {
    const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);
    if (!match?.groups) {
        throw new Error('Invalid CAIP account ID.');
    }
    return {
        address: match.groups.accountAddress,
        chainId: match.groups.chainId,
        chain: {
            namespace: match.groups.namespace,
            reference: match.groups.reference
        }
    };
}

//# sourceMappingURL=caip-types.js.map