def derive(number, harden = false)
      number += HARDENED_THRESHOLD if harden
      new_key = ExtKey.new
      new_key.depth = depth + 1
      new_key.number = number
      new_key.parent_fingerprint = fingerprint
      if number > (HARDENED_THRESHOLD - 1)
        data = [0x00].pack('C') << key.priv_key.htb << [number].pack('N')
      else
        data = key.pubkey.htb << [number].pack('N')
      end
      l = Bitcoin.hmac_sha512(chain_code, data)
      left = l[0..31].bth.to_i(16)
      raise 'invalid key' if left >= CURVE_ORDER
      child_priv = (left + key.priv_key.to_i(16)) % CURVE_ORDER
      raise 'invalid key ' if child_priv >= CURVE_ORDER
      new_key.key = Bitcoin::Key.new(
          priv_key: child_priv.to_even_length_hex.rjust(64, '0'), key_type: key_type)
      new_key.chain_code = l[32..-1]
      new_key.ver = version
      new_key
    end
def derive(number, harden = false)
      number += HARDENED_THRESHOLD if harden
      new_key = ExtKey.new
      new_key.depth = depth + 1
      new_key.number = number
      new_key.parent_fingerprint = fingerprint
      if number > (HARDENED_THRESHOLD - 1)
        data = [0x00].pack('C') << key.priv_key.htb << [number].pack('N')
      else
        data = key.pubkey.htb << [number].pack('N')
      end
      l = Bitcoin.hmac_sha512(chain_code, data)
      left = l[0..31].bth.to_i(16)
      raise 'invalid key' if left >= CURVE_ORDER
      child_priv = (left + key.priv_key.to_i(16)) % CURVE_ORDER
      raise 'invalid key ' if child_priv >= CURVE_ORDER
      new_key.key = Bitcoin::Key.new(
          priv_key: child_priv.to_even_length_hex.rjust(64, '0'), key_type: key_type)
      new_key.chain_code = l[32..-1]
      new_key.ver = version
      new_key
    end
derive new key
 @param [Integer] number a child index
 @param [Boolean] harden whether hardened key or not. If true, 2^31 is added to +number+.
 @return [Bitcoin::ExtKey] derived new key.