Is there a way to create a keypair through the RPC API? Previously, I've been doing this with
cleos wallet create_key or
cleos create key but now I'm building an application that needs to do this programatically.
I would reconsider this approach because it is possible to expose your/the users private key if you rely on a thrid party to create the key. Even if the third party behaves correct, due to transmissions you were also likely to be exposed to middleman attacks.
Also currently there is no RPC call for safely creating key-pairs via 3rd party available.
When you run
nodeos, the RPC is start on the port number 8888.
You can generate new keypair by following method:
Note:- Creates a key within the specified wallet, wallet must be opened and unlocked.
Parameters are: 1.name of the wallet to create key in; 2. type of key to create, currently that support two values: K1 and R1
Run following command in terminal:
$ curl http://127.0.0.1:8888/v1/wallet/create_key -X POST -d '["wallet_name","K1"]'
This command will return the public key of the created key:
If it gives error
wallet doesn't exist, then create wallet by RPC call:
$ curl http://localhost:8888/v1/wallet/create -X POST -d '"wallet_name"'
Then apply first command.