Class: X402::Tasks::WalletSetup
- Inherits:
-
Object
- Object
- X402::Tasks::WalletSetup
- Defined in:
- lib/x402/tasks/wallet_setup.rb
Overview
Interactive wallet setup task — backing implementation for +rake x402:wallet:setup+.
Behaviour:
- Checks BSV_WALLET_DIR/wallet.key (default ~/.bsv-wallet/wallet.key)
- If exists: prints identity key, reports dir, exits cleanly. Never overwrites. Set FORCE=1 to replace an existing wallet.
- If absent: offers [1] create new / [2] restore from WIF / [3] cancel
- New wallets get a random PrivateKey. WIF written with mode 0600.
- Parent directory created with mode 0700.
Designed for dependency injection in tests: pass custom +stdin+, +stdout+, +dir+, and +random_wif+ to the constructor.
Constant Summary collapse
- FORCE_ENV_VAR =
"FORCE"
Instance Method Summary collapse
-
#initialize(stdin: $stdin, stdout: $stdout, dir: nil, random_wif: nil) ⇒ WalletSetup
constructor
A new instance of WalletSetup.
- #run ⇒ Object
Constructor Details
#initialize(stdin: $stdin, stdout: $stdout, dir: nil, random_wif: nil) ⇒ WalletSetup
Returns a new instance of WalletSetup.
33 34 35 36 37 38 39 |
# File 'lib/x402/tasks/wallet_setup.rb', line 33 def initialize(stdin: $stdin, stdout: $stdout, dir: nil, random_wif: nil) require "bsv-sdk" @stdin = stdin @stdout = stdout @dir = dir || ENV.fetch("BSV_WALLET_DIR", X402::Wallet::DEFAULT_DIR) @random_wif = random_wif || -> { ::BSV::Primitives::PrivateKey.generate.to_wif } end |
Instance Method Details
#run ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/x402/tasks/wallet_setup.rb', line 41 def run ensure_dir! if File.exist?(key_path) handle_existing else handle_fresh end end |