```
const r = bytesToNumber(r_bytes);
const P = Point.fromPrivateKey(r);
```
I'm not sure if this is where your bug is happening, but you don't need r
I suggest using Typescript as having stricter types helps find bugs.
I am looking further to see if I can find anything wrong...