import { aggregatePublicKeys } from "@chainsafe/blst";
import { SignatureSetType } from "@lodestar/state-transition";
export function getAggregatedPubkey(signatureSet, pubkeyCache, metrics = null) {
    switch (signatureSet.type) {
        case SignatureSetType.single:
            return signatureSet.pubkey;
        case SignatureSetType.indexed: {
            return pubkeyCache.getOrThrow(signatureSet.index);
        }
        case SignatureSetType.aggregate: {
            const timer = metrics?.blsThreadPool.pubkeysAggregationMainThreadDuration.startTimer();
            const pubkeys = signatureSet.indices.map((i) => {
                return pubkeyCache.getOrThrow(i);
            });
            const aggregated = aggregatePublicKeys(pubkeys);
            timer?.();
            return aggregated;
        }
        default:
            throw Error("Unknown signature set type");
    }
}
export function getAggregatedPubkeysCount(signatureSets) {
    let pubkeysCount = 0;
    for (const set of signatureSets) {
        if (set.type === SignatureSetType.aggregate) {
            pubkeysCount += set.indices.length;
        }
    }
    return pubkeysCount;
}
//# sourceMappingURL=utils.js.map