Is it acceptable to use a HMAC-SHA256 hash as a secp256k1 private key?

Say I want to generate a deterministic private key related to some data, for instance to a domain name. The easiest way I can think of is:

1. take a secret material which will work as "generator".
2. take a domain name and HMAC-SHA256(my secret, domain name).
3. take resulting hash and use it directly as secp256k1 private key.

Question is if that last step is an OK move or are there issues with directly using hash as private key?

• Simple rule of thumb is that the transformation process doesn't matter, the entropy source does. – DannyNiu Sep 12 '20 at 5:21
• @DannyNiu I might add the caveat that if one key is compromised, the transformation method matters very much since you don't want one compromised key leading to the rest of them. But SHA-256 is perfectly good as a transformation method, so in this case OP should be fine. – Serpent27 Sep 12 '20 at 6:12
• What happened to good random source for the key generation? Still you need a key for HMAC that need to be secure. Your input is already known. – kelalaka Sep 12 '20 at 8:23

If your secret material (you call this my secret so I'll use that name) is chosen with sufficient min-entropy, then yes this scheme is acceptable. my secret, however, must be in itself sufficiently hard to guess; it becomes effectively a password cracking problem. As such, I would suggest my secret be a randomly generated keyfile, or at least a really secure password.
It's worth noting that if my secret is found, this system completely fails. So guard my secret very well. Be wary of keyloggers, shoulder surfers, malware, people nearby who happen to have a parabolic microphone (I'm not kidding), suspicious power outlets (also not kidding), and any number of other attack vectors.
• It is worth to add that the probability is $<2^{-127}$ that a random HMAC-SHA-256 result accidentally falls out of the range $[1,2^{256}-\mathtt{14551231950b75fc4402da1732fc9bebf_h})$ of valid secp256k1 private keys; and that it seems infeasible to exhibit an example of the contrary. – fgrieu Sep 12 '20 at 9:24