cashubtc / nutshell

Chaumian ecash wallet and mint for Bitcoin
https://docs.cashu.space
MIT License
379 stars 95 forks source link

binascii.Error: Incorrect padding (local mint) #101

Closed steepdawn974 closed 1 year ago

steepdawn974 commented 1 year ago

Hello,

wanted to play with cashu by setting up a local mint, and mint some tokens. Getting error binascii.Error: Incorrect padding (local mint) when running cashu receive

Steps taken

  1. Install cashu via poetry (per readme)
  2. Create .env file with DEBUG=TRUE, TOR=FALSE, LIGHTNING=FALSE, comment out SOCKS
    
    echo "DEBUG=TRUE

CASHU_DIR=~/.cashu

WALLET

MINT_URL=https://localhost:3338

MINT_HOST=127.0.0.1 MINT_PORT=3338

use builtin tor, this overrides SOCKS_HOST and SOCKS_PORT

TOR=FALSE

use custom tor proxy, use with TOR=false

SOCKS_HOST=localhost

SOCKS_PORT=9050

MINT

MINT_PRIVATE_KEY=supersecretprivatekey

MINT_SERVER_HOST=127.0.0.1 MINT_SERVER_PORT=3338

LIGHTNING=FALSE

fee to reserve in percent of the amount

LIGHTNING_FEE_PERCENT=1.0

minimum fee to reserve

LIGHTNING_RESERVE_FEE_MIN=4000

LNBITS_ENDPOINT=https://legend.lnbits.com LNBITS_KEY=yourkeyasdasdasd

NOSTR

nostr private key to which to receive tokens to

NOSTR_PRIVATE_KEY=hex_nostrprivatekey_here

nostr relays (comma separated list)

NOSTR_RELAYS=\"wss://nostr-pub.wellorder.net\" " > .env

3. Start mint: `poetry run mint`

2023-01-25 11:18:05.24 | INFO | Started server process [282100] 2023-01-25 11:18:05.24 | INFO | Waiting for application startup. 2023-01-25 11:18:05.26 | INFO | Data dir: /home/ingo/.cashu 2023-01-25 11:18:05.26 | INFO | Mint started. 2023-01-25 11:18:05.26 | INFO | Application startup complete. 2023-01-25 11:18:05.26 | INFO | Uvicorn running on http://127.0.0.1:3338 (Press CTRL+C to quit)

5. In new tab:  `cashu receive 100`

23-01-25 11:36:36.044 | DEBUG | cashu.wallet.wallet:init:407 - Wallet initalized with mint URL http://127.0.0.1:3338 Balance: 0 sat 2023-01-25 11:36:36.061 | DEBUG | cashu.wallet.wallet:_load_mint:156 - Mint keysets: ['eNPchHkKANBq'] 2023-01-25 11:36:36.062 | DEBUG | cashu.wallet.wallet:_load_mint:157 - Current mint keyset: eNPchHkKANBq Traceback (most recent call last): File "/home//.pyenv/versions/3.9.13/envs/cashu/bin/cashu", line 6, in sys.exit(cli()) File "/home//.pyenv/versions/3.9.13/envs/cashu/lib/python3.9/site-packages/click/core.py", line 1128, in call return self.main(args, kwargs) File "/home//.pyenv/versions/3.9.13/envs/cashu/lib/python3.9/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/home//.pyenv/versions/3.9.13/envs/cashu/lib/python3.9/site-packages/click/core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home//.pyenv/versions/3.9.13/envs/cashu/lib/python3.9/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "/home//.pyenv/versions/3.9.13/envs/cashu/lib/python3.9/site-packages/click/core.py", line 754, in invoke return __callback(args, kwargs) File "/home//.pyenv/versions/3.9.13/envs/cashu/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func return f(get_current_context(), *args, *kwargs) File "/home//code/cashu/cashu/wallet/cli.py", line 116, in wrapper return asyncio.run(f(args, kwargs)) File "/home//.pyenv/versions/3.9.13/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/home//.pyenv/versions/3.9.13/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "/home//code/cashu/cashu/wallet/cli.py", line 412, in receive_cli await receive(ctx, token, lock) File "/home//code/cashu/cashu/wallet/cli.py", line 357, in receive dtoken = json.loads(base64.urlsafe_b64decode(token)) File "/home//.pyenv/versions/3.9.13/lib/python3.9/base64.py", line 133, in urlsafe_b64decode return b64decode(s) File "/home//.pyenv/versions/3.9.13/lib/python3.9/base64.py", line 87, in b64decode return binascii.a2b_base64(s) binascii.Error: Incorrect padding



### Some general Cashu questions
- How do I actually mint new token in my local mint?
- Is there a documentation about each options in the `.env` file?
    - For instance, what's the differnce between `MINT_HOST` and `MINT_SERVER_HOST` ?
    - How would I connect the CLI to Calle's Mint on Legend LNbits (mint_id=GsAL2UKczDnkS5SWW65GZE) ?
    - can I import tokens from a backup json?
callebtc commented 1 year ago

Hello, thank you for this report!

To your issue

You have used the command cashu receive <token> wrong, there should be a token not an amount there.

Instead, to mint yourself free ecash, you can use cashu invoice 1000 and you will get free money since you've set LIGHTNING=false. This is just for testing and development!

To your questions:

.env variavbles

There are only sporadic comments in the .env.example. MINT_HOST is the host the wallet will connect to. MINT_SERVER_HOST is the host the mint will listen on. Very bad naming, I should add some comments :)

Use a different mint

The mint URL for the lnbits mints is https://legend.lnbits.com/cashu/api/v1/GsAL2UKczDnkS5SWW65GZE (replace ID with mint_id). This is not quite easy to figure out, it's on my todo list.

There are multiple options to use this mint in the CLI:

Thank you for your interest, let me know if anything is unclear and please join our Telegram group: https://t.me/CashuBTC