Util.php 525 B

123456789101112131415161718192021222324
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tk
  5. * Date: 9/25/17
  6. * Time: 2:20 PM
  7. */
  8. namespace BitWasp\Test\Bech32;
  9. class Util
  10. {
  11. public static function witnessProgram($version, $program)
  12. {
  13. if ($version < 0 || $version > 16) {
  14. throw new \RuntimeException("Invalid version for witness program");
  15. }
  16. $version = pack("C", ($version > 0 ? (0x50 + $version) : 0));
  17. $length = pack("C", strlen($program));
  18. return unpack("H*", "{$version}{$length}{$program}")[1];
  19. }
  20. }