kielabokkie / bitcoin-address-validator

PHP package to validate legacy, segwit, native segwit (bech32) and taproot Bitcoin addresses
MIT License
38 stars 8 forks source link

1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i is not recognized (the address from the examples at the repo home page) #7

Closed meglio closed 1 year ago

meglio commented 1 year ago

When running this in Docker Container, PHP 8.1.19:

$validator = new AddressValidator();
$validator->isValid('1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i');

It returns FALSE.

Any ideas?

kielabokkie commented 1 year ago

That's strange, it should work fine on 8.1 as the tests are also run against it.

Is it just that address or do they all fail? Can you maybe provide a docker file so I can replicate the issue?

meglio commented 1 year ago

A docker file for two lines of code?

kielabokkie commented 1 year ago

It was more to see what kind of base image you use and what extensions you have installed etc.

It works fine on Docker locally for me. The Github Actions also run on docker and pass. You are asking for help so the least you can do it provide me with something to replicate your issue. Let me know if that's too much work so I can close the issue.

meglio commented 1 year ago

Hi @kielabokkie . I'm not asking for help indeed, I have solved the problem for my project long time ago by using other libraries, importing functions etc.

I was just trying to be helpful by bringing your attention to the issue.

kielabokkie commented 1 year ago

@meglio I appreciate you are trying to bring my attention to an issue but if I can't replicate the issue it's hard to try and solve it don't you think? From the sound of it, it could be an issue with a missing PHP extension on the Docker container you are using but if you can't share it then I can't do anything to try and investigate further.

As you are unwilling to help me replicate the issue and are using another library, I will close this issue now.

meglio commented 1 year ago

Hi @kielabokkie,

Docker container:

FROM php:8.1.21-fpm

RUN apt-get update && apt-get install -y \
    procps supervisor \
    nano wget zip unzip gnupg libgpgme-dev \
    libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
    lsb-release htop qrencode \
    && apt-get install -y --no-install-recommends libpq-dev libgmp-dev

# The following are needed in dev profile only.
RUN apt-get update && apt-get install -y \
    iputils-ping

RUN docker-php-ext-install pgsql

# RUN docker-php-ext-install pgsql gnupg

# -f, --force - will overwrite newer installed packages
RUN pecl install -f xdebug-3.1.5 && docker-php-ext-enable xdebug
RUN pecl install -f gnupg-1.5.1 && docker-php-ext-enable gnupg

RUN docker-php-ext-install pcntl sysvmsg sysvsem gmp

RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd

# Install postgresql-client so that we can call pg_dump from within the container
RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update && apt-get -y install postgresql-client

### NODE
# Install node. Source: https://github.com/nodesource/distributions#deb
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -y nodejs
# Install global node packages needed for jstools/*
RUN npm install -g lodash@4.17.21 tiny-secp256k1@2.2.1 bitcoinjs-lib@6.1.0 bip32@4.0.0 bip84@0.2.7 bip86@0.0.3
# Create a folder where javascript tools will be placed
RUN mkdir -p /jstools
# Create a node_modules symlink to the global node modules folder, so that the caller can run js and mjs files
RUN ln -s $(npm root -g) /jstools/node_modules
### END NODE

RUN echo 'alias xdebugon='\''export XDEBUG_CONFIG="start_with_request=yes mode=debug" XDEBUG_MODE=debug XDEBUG_SESSION=1'\''' >> ~/.bashrc
RUN echo 'alias xdebugoff='\''export XDEBUG_CONFIG="start_with_request=no mode=off" XDEBUG_MODE=off XDEBUG_SESSION=""'\''' >> ~/.bashrc
RUN echo 'alias xdebugprofile='\''export XDEBUG_CONFIG="start_with_request=0" XDEBUG_MODE=profile'\''' >> ~/.bashrc

# Use the default development configuration
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

EXPOSE 9555
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

PHP INI file 1: shared.php.ini

# PHP configuration shared between all environments.

# Don't create the X-Powered-By header
expose_php = Off

max_input_vars = 3000
date.timezone = UTC
upload_max_filesize = 20M
max_post_size = 22MB
memory_limit = 300M

PHP INI file 2: dev.php.ini

# PHP configuration specific to development environment.

display_errors=On
display_startup_errors=On

[xdebug]
# Source: https://stackoverflow.com/a/38267548/335304

# ... off,develop,coverage,debug,gcstats,profile,trace
xdebug.mode=debug
xdebug.start_with_request=default
xdebug.discover_client_host=1
xdebug.idekey=PHPIDE
xdebug.client_host=host.docker.internal
xdebug.client_port=9005
xdebug.output_dir=/cache/xdebug
xdebug.var_display_max_children = 999
xdebug.var_display_max_data = 999
xdebug.var_display_max_depth = 100

composer.json

{
    "name": "xxx/yyy",
    "description": "Test",
    "type": "project",
    "readme": "README.md",
    "license": "proprietary",
    "config": {
        "vendor-dir": "src/php/vendor"
    },
    "autoload": {
        "psr-4": {
            "Bot\\": "src/php/"
        }
    },
    "require": {
        "php": "^8.1",
        "ext-gd": "*",
        "ext-pgsql": "*",
        "ext-curl": "*",
        "ext-sysvsem": "*",
        "ext-pcntl": "*",
        "ext-sysvmsg": "*",
        "ext-posix": "*",
        "ext-mbstring": "*",
        "ext-gmp": "*",
        "ext-gnupg": "*",
        "ext-ctype": "*",
        "ext-fileinfo": "*",
        "ext-readline": "*",
        "ext-sodium": "*",
        "imagine/imagine": "^1.3.3",
        "phpseclib/phpseclib": "3.0.19",
        "fakerphp/faker": "1.21.0",
        "ezyang/htmlpurifier": "^4.16",
        "hidehalo/nanoid-php": "^1.1",
        "nette/php-generator": "^4.0",
        "rinvex/countries": "^9.0"
    }
}

Any chance you could look at it with using these files?

kielabokkie commented 1 year ago

Thanks for providing these @meglio. I'll have a play around and let you know what I can find out.

kielabokkie commented 1 year ago

@meglio I just tested it with the config you provided and it's only one small change to make it work.

In your Dockerfile on the line where you have RUN docker-php-ext-install pcntl sysvmsg sysvsem gmp you have to add bcmath, i.e. RUN docker-php-ext-install pcntl sysvmsg sysvsem gmp bcmath.

Let me know if that fixes the problem for you.

meglio commented 1 year ago

Thanks for getting back to me. Hm that's interesting, the fact that it fails quietely and gives wrong answer is not good. Any way to make it fail with an exception instead of giving an incorrect answer?

kielabokkie commented 1 year ago

@meglio This has been added in v2.2.0