./recover.sh
spawn grin-wallet --api_server_address 'https://grinnode.live' -t recover init -r
Please enter your recovery phrase:
phrase> essence bring faith welcome bubble vault bar begin twenty okay child bundle remind people wheel reopen board oak grow alpha crumble steak more scrap
Please provide a new password for the recovered wallet
Password:
Confirm Password:
20211106 22:07:26.567 WARN grin_wallet_impls::lifecycle::seed - Generating wallet seed file at: recover/wallet_data/wallet.seed
Your recovery phrase is:
essence bring faith welcome bubble vault bar begin twenty okay child bundle remind people wheel reopen board oak grow alpha crumble steak more scrap
Please back-up these words in a non-digital format.
Command 'init' completed successfully
ok
Script:
cat recover.sh
#!/usr/bin/expect
set seed "essence bring faith welcome bubble vault bar begin twenty okay child bundle remind people wheel reopen board oak grow alpha crumble steak more scrap"
set password ""
spawn grin-wallet --api_server_address 'https://grinnode.live:3413' -t recover init -r
expect "Please enter your recovery phrase:"
send "$seed\r"
expect "Password:"
send "$password\r"
expect "Confirm Password:"
send "$password\r"
expect "Command 'init' completed successfully"
puts "ok\n"
Info:
It used the Grinnode.live API for recovering, but you need to use your local node to be on the safe side.
also recovery phrases are hard coded into the script, which is not good. This is just a PoC.
When I run PHP exec (‘expect recover.sh’) I get: Wallet command failed: Parsing IO error: terminfo entry not found
When I run PHP exec(‘sh recover.sh’) I get a 127 return code and no output.
When I run it in the terminal manually it works.
@mcm-mike I’m pretty sure expect requires a terminal on some screen, meaning there is no programmatical solution, just some partially working hack with expect
I really think that the devs should just add a --phrase option so that it can be used normally
Or is there some conspiracy to not allow automated systems with grin
I am not an PHP expert, but if you want to run bash “code” in PHP you need do use something,which is really insecure and should not be used shell_exec.
@mcm-mike I’m pretty sure expect requires a terminal on some screen, meaning there is no programmatical solution, just some partially working hack with expect
yes my script requires an SSH access to get a bash or sh shell to run it and it needs to have expect also installed (should be usually). This is just a PoC not a working prototype please keep this in mind.
I really think that the devs should just add a --phrase option so that it can be used normally
I think there are some public solutions on how to do it, but we need to wait for other users to reply here.
I havent coded in rust before, is there a way that I can hack this and get it to detect the parameter?
I tried here but I don’t think &args.phrase is correct.
grin@debian:~/grin/grinmw.py/grinmw$ python3.9 test.py
Traceback (most recent call last):
File "/home/grin/grin/grinmw.py/grinmw/test.py", line 14, in <module>
wallet.init_secure_api()
File "/home/grin/grin/grinmw.py/grinmw/wallet_v3.py", line 105, in init_secure_api
resp = self.post('init_secure_api', {'ecdh_pubkey': pubkey})
File "/home/grin/grin/grinmw.py/grinmw/wallet_v3.py", line 65, in post
raise WalletError(method, params, response.status_code, response.reason)
wallet_v3.WalletError: Callng init_secure_api with params {'ecdh_pubkey': '02e66f5ccab6b1eb1734c2ef956aeba3eed8f50db4cdf5adbf205d40556dd5025c'} failed with error code 404 because: Not Found
grin@debian:~/grin/grinmw.py/grinmw$
That looks like it cannot reach the API. I see you have
api_url = 'http://localhost:3413/v3/owner'
while it should be
api_url = 'http://localhost:3413/v2/owner'
I don’t think we have v3 yet. (someone correct me if I’m wrong)
Pull requests always welcome bro!
Edit: Sorry, I confused with the node API, for wallet yes, there is v3. @harry.potter it looks strangely similar to your bug with the local node. Are you able to run local listeners for other server-like apps? Could there be some problem with your /etc/hosts? Maybe you can try to replace localhost with 127.0.0.1 in your url?
The Grin wallet should implement program arguments as an alternative to starting the program and providing input. For all parameters that require manual input. This will end the era of everybody who isnt using the api having to depend on expect and pexpect to communicate with the wallet and will aid all developers who have taken any interest in grin.
It would be helpful to know the http response status code. For instance, if it is 500 - internal server error then you should check wallet / node logs.
Could you try to provide more details? Some sort of verbose log output.
You mean, something like providing arguments by command line pipe?
Yes, exactly. You should be able to provide a command-line argument as a recovery phrase, when it comes to slatepacks maybe you could pipe in the file or pass a parameter with the file path.
using ‘expect’ is not the best solution, because what happens when you want to execute in a way that has no interface to a graphical terminal with human input, you can’t interact with the rust client with ‘expect’.
It’s important that the main implementation is usable.
I tried my hand at rust, but I really need to watch a course on it or something because its syntax or object types is alien to me.
‘expect’ and ‘pexpect’ is a bit of a hack let’s admit it. forcing everyone down that road is wrong.
I see value in being able to provide seed phrase using the arguments as that would allow to script the wallet workflow, however not sure if providing seed phrase directly is a good idea as by default the commands get logged and first thing one does after breaking into someones server is checking the command line log.
Maybe better to put seed phrase in a file and provide path to the file as an argument?
There is a feature wishlist thread on GitHub, feel free to add your ideas and members of the core dev team will review them and consider.