A person offending against any provision of this title is a competent witness against another person so offending, and may be compelled to attend and testify upon any trial, hearing, proceeding, or investigation, in the same manner as any other person. But the testimony so given shall not be used in any prosecution or proceeding, civil or criminal, against the person so testifying, and he shall not thereafter be liable to prosecution or punishment for the offense with reference to which his testimony was given.
SDCL 12-26-31