<commit_before><?php

namespace BitWasp\Bitcoin\Key;

use BitWasp\Bitcoin\Crypto\Hash;
use BitWasp\Bitcoin\Key\PrivateKeyInterface;
use BitWasp\Bitcoin\Crypto\EcAdapter\EcAdapterInterface;
use BitWasp\Buffertools\Buffer;

class Electrum
{
    private $ecAdapter;

    /**
     * @var PrivateKeyInterface|PublicKeyInterface
     */
    private $masterKey;

    /**
     * @param EcAdapterInterface $ecAdapter
     * @param KeyInterface|PrivateKeyInterface|PublicKeyInterface $masterKey
     */
    public function __construct(EcAdapterInterface $ecAdapter, KeyInterface $masterKey)
    {
        $this->ecAdapter = $ecAdapter;
        $this->masterKey = $masterKey;
    }

    /**
     * @return PublicKeyInterface
     */
    public function getMasterPublicKey()
    {
        $key = $this->masterKey;

        return $key instanceof PrivateKeyInterface
            ? $this->masterKey->getPublicKey()
            : $this->masterKey;
    }

    /**
     * @param $sequence
     * @param bool $change
     * @return int|string
     */
    public function getSequenceOffset($sequence, $change = false)
    {
        $offsetBuf = new Buffer("$sequence:"
            . ($change ? '1' : '0')
            . $this->getMasterPublicKey()->getBinary());

        return Hash::sha256d($offsetBuf)->getInt();
    }

    /**
     * @param $sequence
     * @param bool $change
     */
    public function deriveChild($sequence, $change = false)
    {
        $key = $this->masterKey;

        
    }
}<commit_msg>Expose a nice tidy deriveChild function for Electrum<commit_after><?php

namespace BitWasp\Bitcoin\Key;

use BitWasp\Bitcoin\Crypto\Hash;
use BitWasp\Bitcoin\Key\PrivateKeyInterface;
use BitWasp\Bitcoin\Crypto\EcAdapter\EcAdapterInterface;
use BitWasp\Buffertools\Buffer;

class Electrum
{
    private $ecAdapter;

    /**
     * @var PrivateKeyInterface|PublicKeyInterface
     */
    private $masterKey;

    /**
     * @param EcAdapterInterface $ecAdapter
     * @param KeyInterface|PrivateKeyInterface|PublicKeyInterface $masterKey
     */
    public function __construct(EcAdapterInterface $ecAdapter, KeyInterface $masterKey)
    {
        $this->ecAdapter = $ecAdapter;
        $this->masterKey = $masterKey;
    }

    /**
     * @return PublicKeyInterface
     */
    public function getMasterPublicKey()
    {
        $key = $this->masterKey;

        return $key instanceof PrivateKeyInterface
            ? $this->masterKey->getPublicKey()
            : $this->masterKey;
    }

    /**
     * @param $sequence
     * @param bool $change
     * @return int|string
     */
    public function getSequenceOffset($sequence, $change = false)
    {
        $offsetBuf = new Buffer("$sequence:"
            . ($change ? '1' : '0')
            . $this->getMasterPublicKey()->getBinary());

        return Hash::sha256d($offsetBuf)->getInt();
    }

    /**
     * @param $sequence
     * @param bool $change
     * @return PrivateKeyInterface|PublicKeyInterface
     */
    public function deriveChild($sequence, $change = false)
    {
        return $this->masterKey->tweakAdd($this->getSequenceOffset($sequence, $change));
    }
}
{'fraction_non_alphanumeric': 0.12344497607655502, 'fraction_numerical': 0.003189792663476874, 'mean_word_length': 2.6296296296296298, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3265947', 'n_tokens_mistral': 930, 'n_tokens_neox': 908, 'n_words': 172}