export const isSigner = (input) => {
    return (typeof input === 'object' &&
        'publicKey' in input &&
        ('secretKey' in input || 'signTransaction' in input));
};
export const isKeypairSigner = (input) => {
    return isSigner(input) && 'secretKey' in input && input.secretKey != null;
};
export const isIdentitySigner = (input) => {
    return isSigner(input) && !isKeypairSigner(input);
};
export const getSignerHistogram = (signers) => signers.reduce((signers, signer) => {
    var _a;
    const duplicateIndex = signers.all.findIndex(({ publicKey }) => publicKey.equals(signer.publicKey));
    const duplicate = (_a = signers.all[duplicateIndex]) !== null && _a !== void 0 ? _a : null;
    const duplicateIsIdentity = duplicate
        ? isIdentitySigner(duplicate)
        : false;
    const signerIsIdentity = isIdentitySigner(signer);
    if (!duplicate) {
        signers.all.push(signer);
        if (signerIsIdentity) {
            signers.identities.push(signer);
        }
        else {
            signers.keypairs.push(signer);
        }
    }
    else if (duplicateIsIdentity && !signerIsIdentity) {
        // Prefer keypair than identity signer as it requires less user interactions.
        const duplicateIdentitiesIndex = signers.identities.findIndex(({ publicKey }) => publicKey.equals(signer.publicKey));
        signers.all.splice(duplicateIndex, 1);
        signers.identities.splice(duplicateIdentitiesIndex, 1);
        signers.all.push(signer);
        signers.keypairs.push(signer);
    }
    return signers;
}, { all: [], keypairs: [], identities: [] });
//# sourceMappingURL=Signer.js.map