Method of recovering precious metals and rare-earth elements from waste materials