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.
3 Answers
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:
EOS6GZE1xeo6jX2AtP2Z6WTcxawQMH7cyYMNpG6Q3q7s514zyRhgo
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.
Are you trying to use a Block Producer API endpoint to do the HTTP RPC calls for wallet creation? If you run your own test node, you can pretty much follow the examples that are shown in the reference you mentioned. They are all curl examples but they can be implemented using any web client.
-
The wallet can easily be created through an RPC call; however, no RPC call exists for creating keypairs nor accounts.– AnconiaCommented Jun 26, 2018 at 5:04
-
Agreed. Can you use ideas from github.com/nsjames/Scatter/blob/master/src/cryptography/…– KabirCommented Jun 26, 2018 at 5:39