code: function P_hash(secret, seed, outputLength, algorithm) {
      let result = Buffer.alloc(0); // empty buffer
      let hmac;
  
      // for the initial iteration, set the (initial) data to our seed
      let data = seed;
      while (result.length < outputLength) {
          // calculate the hmac for our current 'data' value (our seed on the initiatial iteration...or an iterative hmac of that seed in later iterations)
          hmac = exports.crypto.createHmac(algorithm, secret).update(data).digest();
          // save this hmac result as the 'data' input for the next iteration
          let dataForNextIteration = hmac;
          // concatenate the hmac and our seed
          data = Buffer.concat([hmac, seed]);
          // calculate an hmac for the hmac-plus-seed (which we will store in our output)
          hmac = exports.crypto.createHmac(algorithm, secret).update(data).digest();
          // add the hmac to our result
          result = Buffer.concat([result, hmac]);
          // restore the saved first-interation-stage hmac as the 'data' input for our next iteration
          data = dataForNextIteration;
      }
  
      // if our HMAC's output block size resulted in a length which is slightly too big, discard the extra bytes.
      if (result.length > outputLength) {
          let truncatedBuffer = Buffer.alloc(outputLength);
          result.copy(truncatedBuffer, 0, 0, outputLength);
          result = truncatedBuffer;
      }
  
      // return the hash result (with the number of octects/bytes specified as 'outputLength' by the caller)
      return result;
  }
docs: P_hash expands a secret and seed into an arbitrary quantity of output data /* P_hash input parameters:
  secret: hash secret
  seed: hash seed
  outputLength: number of bytes to return
  algorithm: hash algorithm {'HMAC','SHA1'}