code: function deterministicGenerateK(curve, hash, d, checkSig, nonce) {
      enforceType("Buffer", hash);
      enforceType(BigInteger, d);
  
      if (nonce) {
          hash = sha256(Buffer.concat([hash, Buffer.alloc(nonce)]));
      }
  
      // sanity check
      assert.equal(hash.length, 32, "Hash must be 256 bit");
  
      var x = d.toBuffer(32);
      var k = Buffer.alloc(32);
      var v = Buffer.alloc(32);
  
      // Step B
      v.fill(1);
  
      // Step C
      k.fill(0);
  
      // Step D
      k = HmacSHA256(Buffer.concat([v, new Buffer([0]), x, hash]), k);
  
      // Step E
      v = HmacSHA256(v, k);
  
      // Step F
      k = HmacSHA256(Buffer.concat([v, new Buffer([1]), x, hash]), k);
  
      // Step G
      v = HmacSHA256(v, k);
  
      // Step H1/H2a, ignored as tlen === qlen (256 bit)
      // Step H2b
      v = HmacSHA256(v, k);
  
      var T = BigInteger.fromBuffer(v);
  
      // Step H3, repeat until T is within the interval [1, n - 1]
      while (T.signum() <= 0 || T.compareTo(curve.n) >= 0 || !checkSig(T)) {
          k = HmacSHA256(Buffer.concat([v, new Buffer([0])]), k);
          v = HmacSHA256(v, k);
  
          // Step H1/H2a, again, ignored as tlen === qlen (256 bit)
          // Step H2b again
          v = HmacSHA256(v, k);
  
          T = BigInteger.fromBuffer(v);
      }
  
      return T;
  }
docs: https://tools.ietf.org/html/rfc6979#section-3.2