Create account using API

I would like to use the API I can see in Dev Tools’ Network tab, but I’m having some issues. When I am trying to register a user through the API, I see that the following JSON is sent to /api/accounts/register

{
"name": "myname",
"email": "myemail@gmail.com",
"masterPasswordHash": "ahashedpass",
"masterPasswordHint": null,
"key": "mykey",
"kdf": 0,
"kdfIterations": 100000,
"referenceData": {
	"id": null
},
"keys": {
	"publicKey": "mypublickey",
	"encryptedPrivateKey": "myprivatekey"
}

}

How should I hash the Password?
How should I generate the Key?
How should I generate publicKey and encryptedPrivateKey?

Check the source of bitwarden/web on how this is done