library SigTools {

    /// @notice Splits a signature into r & s values, and v (the verification value).
    /// @dev Note: This does not verify the version, but does require signature length = 65
    /// @param signature the packed signature to be split
    function _splitSignature(bytes memory signature) internal pure returns (bytes32 r, bytes32 s, uint8 v) {
        // Check signature length
        require(signature.length == 65, "Invalid signature length");

        // We need to unpack the signature, which is given as an array of 65 bytes (like eth.sign)
        // solium-disable-next-line security/no-inline-assembly
        assembly {
            r := mload(add(signature, 32))
            s := mload(add(signature, 64))
            v := and(mload(add(signature, 65)), 255)
        }

        if (v < 27) {
            v += 27; // Ethereum versions are 27 or 28 as opposed to 0 or 1 which is submitted by some signing libs
        }

        // check for valid version
        // removed for now, done in another function
        //require((v == 27 || v == 28), "Invalid signature version");

        return (r, s, v);
    }
}
/// @title Signature utility library
function _splitSignature(bytes memory signature) internal pure returns (bytes32 r, bytes32 s, uint8 v) {
    // Check signature length
    require(signature.length == 65, "Invalid signature length");

    // We need to unpack the signature, which is given as an array of 65 bytes (like eth.sign)
    // solium-disable-next-line security/no-inline-assembly
    assembly {
        r := mload(add(signature, 32))
        s := mload(add(signature, 64))
        v := and(mload(add(signature, 65)), 255)
    }

    if (v < 27) {
        v += 27; // Ethereum versions are 27 or 28 as opposed to 0 or 1 which is submitted by some signing libs
    }

    // check for valid version
    // removed for now, done in another function
    //require((v == 27 || v == 28), "Invalid signature version");

    return (r, s, v);
}

/// @notice Splits a signature into r & s values, and v (the verification value).
/// @dev Note: This does not verify the version, but does require signature length = 65
/// @param signature the packed signature to be split