How to obtain a secure copy of macOS?
The only reliable (and legal) source of macOS is the Mac App Store. 

There are python scripts to download from Apple as well. Apple code signs the installers, so you are taking on risk to re-implement or bypass those checks.