Creating a basic SHA256 hasher in Circom

I want to create a SHA256 hasher in Circom so I can validate that a person knows the pre-image of a SHA256 hash without revealing the pre-image. This is my current code but it doesn’t work:

include "/node_modules/circomlib/circuits/sha256/sha256.circom"

template SHAHasher(nBits) {
  signal input bits[nBits];
  signal output newHash[256];

  component shaHash = Sha256(nBits);

  for (var i=0; i<nBits; i++) {[i] <== bits[i];

  for (var i=0; i<256; i++) {
    newHash[i] <== shaHash.out[i];

Thank you in advance, any help would be greatly appreciated.