NAME

Bitcoin::Crypto::Segwit

SYNOPSIS

DESCRIPTION

FUNCTIONS

validate_program

        sig: validate_program($program)

Performs a segwit program validation on $program, which is expected to be a byte string in which the first byte is a segwit version. Based on this version a validator is invoked, present in %Bitcoin::Crypto::Segwit::validators module hash. If the validator is not defined for a segwit version being validated, a warning is issued.

The function returns a detected segwit program version. Please note that it does not perform any more checks than ensuring the byte string is in correct format.

The current implementation defines a validator for segwit version 0. In the future (when another segwit program version is defined) it might be neccessary to define another one in the program until it's added to the library. This can be done like so:

        use Bitcoin::Crypto::Segwit;
        use Bitcoin::Crypto::Exception;

        $Bitcoin::Crypto::Segwit::validators{1} = sub {
                my ($data) = @_;

                # perform validation
                Bitcoin::Crypto::Exception::SegwitProgram->raise(
                        "validation of program version 1 failed"
                ) if ...;

                # if validation is successful just do nothing
                return;
        };

EXCEPTIONS

This module throws an instance of Bitcoin::Crypto::Exception if it encounters an error. It can produce the following error types from the Bitcoin::Crypto::Exception namespace:

  • SegwitProgram - a validation of a segwit program has failed

SEE ALSO

Bitcoin::Crypto::Exception
Bitcoin::Crypto::Bech32