GithubHelp home page GithubHelp logo

Comments (4)

denpamusic avatar denpamusic commented on September 2, 2024

Hi,

There's no real benefits to having an additional config value for passphrase, but it introduces issue with multi-wallet support as well as adds additional complication of having list of methods that require passphrase in client and keeping this list up to date with current Bitcoin Core API.

Hovewer, you can just call WalletPassphrase method before issuing your other commands, that require unlocked wallet, and calling WalletLock after you done.

$bitcoind->walletPassphrase('your_passphrase', 60);
...
// do your operations, that require wallet passphrase here
...
$bitcoind->walletLock();

For convenience sake, you can wrap it in function like this:

use Denpa\Bitcoin\Client as BitcoinClient;

function walletUnlock(BitcoinClient $bitcoind, string $passphrase, callable $fn, int $timeout = 60) : void {
  if ($fn) {
    $bitcoind->walletPassphrase($passphrase, $timeout);
    $fn($bitcoind)
    $bitcoind->walletLock();
  }
}

// then call it like this
walletUnlock($bitcoind, 'your_passphrase', function($bitcoind) {
    // do your operations, that require wallet passphrase here, e. g.
    // $bitcoind->sendToMany(...);
});

That being said, having encrypted wallet and storing passphrase in plain text kind of defeats a whole purpoise of having an encrypted wallet anyway...

from php-bitcoinrpc.

mbsaberi avatar mbsaberi commented on September 2, 2024

Thank you @denpamusic for the reply. I thought using such config may let developer to have less coding for each transaction. However, it is a practical way.
Regarding to your last sentence, I think having a wallet without passphrase is dangerous, and developing a platform based on an encrypted wallet has another danger of using that passphrase in the codes. The only thing I can imagine is having an encrypted file containing that passphrase.

from php-bitcoinrpc.

denpamusic avatar denpamusic commented on September 2, 2024

Thank you for you feedback.

I understand your idea. If possible I still don't want to maintain a list of methods requiring unlocked wallet, since one of advantages of this client is that it doesn't require any update when Core API changes in any way.

If you're ok with manually telling client when you need to unlock wallet, I can implement such configuration parameter using the method I've mentioned above:

use Denpa\Bitcoin\Client as BitcoinClient;

$bitcoind = new BitcoinClient([
    ...
    'passphrase' => 'your_passphrase',
    ...
]);

// when you'll need to execute some commands that require passphrase,
// you'll do it like this:
$bitcoind->withPassphrase(function ($bitcoind) {
    $bitcoind->sendToMany(...);
    ...
});

from php-bitcoinrpc.

mbsaberi avatar mbsaberi commented on September 2, 2024

@denpamusic, thank you for your attention.
As using passphrase needs a time in seconds too, and it may differ for each Bitcoin Core action, I think the best solution is unlocking the wallet for each action (Your first reply). Having a fixed time duration in the config is not practical as methods may need different time periods.

$bitcoind->walletPassphrase('your_passphrase', 60);
...
// do your operations, that require wallet passphrase here
...
$bitcoind->walletLock();

from php-bitcoinrpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.