| @@ -136,16 +136,16 @@ discard block | ||
| 136 | 136 | |
| 137 | 137 | public function isP2SH(): bool | 
| 138 | 138 |      { | 
| 139 | - return 3 === \count($this->cmds) | |
| 139 | + return 3 === \count($this->cmds) | |
| 140 | 140 | && $this->cmds[0] === OpCodes::OP_HASH160->value | 
| 141 | 141 | && \is_string($this->cmds[1]) | 
| 142 | - && 20 === \strlen($this->cmds[1]) | |
| 142 | + && 20 === \strlen($this->cmds[1]) | |
| 143 | 143 | && $this->cmds[2] === OpCodes::OP_EQUAL->value; | 
| 144 | 144 | } | 
| 145 | 145 | |
| 146 | 146 | public function isP2WPKH(): bool | 
| 147 | 147 |      { | 
| 148 | - return 2 === \count($this->cmds) | |
| 148 | + return 2 === \count($this->cmds) | |
| 149 | 149 | && $this->cmds[0] === OpCodes::OP_0->value | 
| 150 | 150 | && \is_string($this->cmds[1]) | 
| 151 | 151 | && 20 === \strlen($this->cmds[1]); | 
| @@ -153,7 +153,7 @@ discard block | ||
| 153 | 153 | |
| 154 | 154 | public function isP2WSH(): bool | 
| 155 | 155 |      { | 
| 156 | - return 2 === \count($this->cmds) | |
| 156 | + return 2 === \count($this->cmds) | |
| 157 | 157 | && $this->cmds[0] === OpCodes::OP_0->value | 
| 158 | 158 | && \is_string($this->cmds[1]) | 
| 159 | 159 | && 32 === \strlen($this->cmds[1]); | 
| @@ -11,7 +11,7 @@ discard block | ||
| 11 | 11 |  { | 
| 12 | 12 | public \GMP $num; | 
| 13 | 13 | |
| 14 | - public function __construct(\GMP|int|string $number) | |
| 14 | + public function __construct(\GMP | int | string $number) | |
| 15 | 15 |      { | 
| 16 | 16 |          if (\is_int($number)) { | 
| 17 | 17 | $number = gmp_init($number); | 
| @@ -19,8 +19,7 @@ discard block | ||
| 19 | 19 | |
| 20 | 20 |          if (\is_string($number)) { | 
| 21 | 21 | $number = str_starts_with($number, '0x') ? | 
| 22 | - gmp_init($number) : | |
| 23 | - gmp_import($number); | |
| 22 | + gmp_init($number) : gmp_import($number); | |
| 24 | 23 | } | 
| 25 | 24 | |
| 26 | 25 |          if ($number < 0 || S256Params::P() <= $number) { | 
| @@ -50,7 +49,7 @@ discard block | ||
| 50 | 49 | return new self(($this->num * gmp_powm($divisor->num, S256Params::P() - 2, S256Params::P())) % S256Params::P()); | 
| 51 | 50 | } | 
| 52 | 51 | |
| 53 | - public function exp(\GMP|int $exponent): self | |
| 52 | + public function exp(\GMP | int $exponent): self | |
| 54 | 53 |      { | 
| 55 | 54 | return new self(gmp_powm($this->num, $exponent % (S256Params::P() - 1), S256Params::P())); | 
| 56 | 55 | } | 
| @@ -57,15 +57,14 @@ discard block | ||
| 57 | 57 | } | 
| 58 | 58 | |
| 59 | 59 | $lam = $this->equals($other) ? | 
| 60 | - new S256Field(3)->mul($this->x->exp(2))->mul(new S256Field(2)->mul($this->y)->exp(S256Params::P() - 2)) : | |
| 61 | - $other->y->sub($this->y)->mul($other->x->sub($this->x)->exp(S256Params::P() - 2)); | |
| 60 | + new S256Field(3)->mul($this->x->exp(2))->mul(new S256Field(2)->mul($this->y)->exp(S256Params::P() - 2)) : $other->y->sub($this->y)->mul($other->x->sub($this->x)->exp(S256Params::P() - 2)); | |
| 62 | 61 | |
| 63 | 62 | $x3 = $lam->mul($lam)->sub($this->x)->sub($other->x); | 
| 64 | 63 | |
| 65 | 64 | return new self($x3, $this->x->sub($x3)->mul($lam)->sub($this->y)); | 
| 66 | 65 | } | 
| 67 | 66 | |
| 68 | - public function scalarMul(\GMP|int $coefficient): self | |
| 67 | + public function scalarMul(\GMP | int $coefficient): self | |
| 69 | 68 |      { | 
| 70 | 69 | // Optimization: reduce the coefficient modulo N before computing the multiplication | 
| 71 | 70 | $c = $coefficient % S256Params::N(); | 
| @@ -109,8 +108,7 @@ discard block | ||
| 109 | 108 | $beta = $alpha->sqrt(); | 
| 110 | 109 | |
| 111 | 110 | return "\x02" === $sec[0] ? | 
| 112 | - new self($x, (0 == $beta->num % 2) ? $beta : new S256Field(S256Params::P() - $beta->num)) : | |
| 113 | - new self($x, (0 == $beta->num % 2) ? new S256Field(S256Params::P() - $beta->num) : $beta); | |
| 111 | + new self($x, (0 == $beta->num % 2) ? $beta : new S256Field(S256Params::P() - $beta->num)) : new self($x, (0 == $beta->num % 2) ? new S256Field(S256Params::P() - $beta->num) : $beta); | |
| 114 | 112 | } | 
| 115 | 113 | |
| 116 | 114 | public function address(bool $compressed = true, Network $mode = Network::TESTNET): string | 
| @@ -133,7 +131,7 @@ discard block | ||
| 133 | 131 |      { | 
| 134 | 132 | $sInv = gmp_powm($sig->s, S256Params::N() - 2, S256Params::N()); | 
| 135 | 133 | |
| 136 | - $u = ($z * $sInv) % S256Params::N(); | |
| 134 | + $u = ($z * $sInv) % S256Params::N(); | |
| 137 | 135 | $v = ($sig->r * $sInv) % S256Params::N(); | 
| 138 | 136 | |
| 139 | 137 | $R = S256Params::G()->scalarMul($u)->add($this->scalarMul($v)); | 
| @@ -50,8 +50,7 @@ discard block | ||
| 50 | 50 | |
| 51 | 51 |          foreach ($this->levels as $level) { | 
| 52 | 52 | [$key, $chainCode] = $key instanceof PrivateKey ? | 
| 53 | - CKDFunctions::CKDPriv($key, $chainCode, $level) : | |
| 54 | - CKDFunctions::CKDPub($key, $chainCode, $level); | |
| 53 | + CKDFunctions::CKDPriv($key, $chainCode, $level) : CKDFunctions::CKDPub($key, $chainCode, $level); | |
| 55 | 54 | |
| 56 | 55 | $extendedKey = new ExtendedKey( | 
| 57 | 56 | $extendedKey->version, | 
| @@ -78,8 +77,7 @@ discard block | ||
| 78 | 77 | $keys = []; | 
| 79 | 78 |          for ($i = $offset; $i < $offset + $limit; ++$i) { | 
| 80 | 79 | $keys[] = $extendedKey->key instanceof PrivateKey ? | 
| 81 | - CKDFunctions::CKDPriv($extendedKey->key, $extendedKey->chainCode, $i)[0] : | |
| 82 | - CKDFunctions::CKDPub($extendedKey->key, $extendedKey->chainCode, $i)[0]; | |
| 80 | + CKDFunctions::CKDPriv($extendedKey->key, $extendedKey->chainCode, $i)[0] : CKDFunctions::CKDPub($extendedKey->key, $extendedKey->chainCode, $i)[0]; | |
| 83 | 81 | } | 
| 84 | 82 | |
| 85 | 83 | return $keys; | 
| @@ -18,9 +18,9 @@ | ||
| 18 | 18 | public string $parentFingerprint; | 
| 19 | 19 | public int $childNumber; | 
| 20 | 20 | public string $chainCode; | 
| 21 | - public PrivateKey|S256Point $key; | |
| 21 | + public PrivateKey | S256Point $key; | |
| 22 | 22 | |
| 23 | - public function __construct(Version $version, int $depth, string $parentFingerprint, int $childNumber, string $chainCode, PrivateKey|S256Point $key) | |
| 23 | + public function __construct(Version $version, int $depth, string $parentFingerprint, int $childNumber, string $chainCode, PrivateKey | S256Point $key) | |
| 24 | 24 |      { | 
| 25 | 25 |          if (0 === $depth && self::MASTER_FINGERPRINT !== $parentFingerprint) { | 
| 26 | 26 |              throw new \InvalidArgumentException('An extended key of depth 0 cannot have a parent fingerprint'); | 
| @@ -54,8 +54,7 @@ discard block | ||
| 54 | 54 | rewind($stream); | 
| 55 | 55 | |
| 56 | 56 | return $segwit ? | 
| 57 | - self::parseSegWit($stream, $mode) : | |
| 58 | - self::parseLegacy($stream, $mode); | |
| 57 | + self::parseSegWit($stream, $mode) : self::parseLegacy($stream, $mode); | |
| 59 | 58 | } | 
| 60 | 59 | |
| 61 | 60 | public function serialize(): string | 
| @@ -74,8 +73,7 @@ discard block | ||
| 74 | 73 | $witness .= Encoding\VarInt::encode(\count($txIn->witness)); | 
| 75 | 74 |                  foreach ($txIn->witness as $element) { | 
| 76 | 75 | $witness .= \is_int($element) ? | 
| 77 | - Encoding\Endian::toLE(gmp_init($element)) : | |
| 78 | - Encoding\VarInt::encode(\strlen($element)).$element; | |
| 76 | + Encoding\Endian::toLE(gmp_init($element)) : Encoding\VarInt::encode(\strlen($element)).$element; | |
| 79 | 77 | } | 
| 80 | 78 | } | 
| 81 | 79 | } | 
| @@ -97,12 +95,12 @@ discard block | ||
| 97 | 95 | |
| 98 | 96 | public function isCoinbase(): bool | 
| 99 | 97 |      { | 
| 100 | - return 1 === \count($this->txIns) | |
| 98 | + return 1 === \count($this->txIns) | |
| 101 | 99 | && '0000000000000000000000000000000000000000000000000000000000000000' === $this->txIns[0]->prevTxId | 
| 102 | - && 0xFFFFFFFF === $this->txIns[0]->prevIndex; | |
| 100 | + && 0xFFFFFFFF === $this->txIns[0]->prevIndex; | |
| 103 | 101 | } | 
| 104 | 102 | |
| 105 | - public function blockHeight(): int|false | |
| 103 | + public function blockHeight(): int | false | |
| 106 | 104 |      { | 
| 107 | 105 |          if (!$this->isCoinbase()) { | 
| 108 | 106 | return false; | 
| @@ -114,7 +114,7 @@ | ||
| 114 | 114 | $acc = 0; | 
| 115 | 115 | $bits = 0; | 
| 116 | 116 | $ret = []; | 
| 117 | - $maxv = (1 << $toBits) - 1; | |
| 117 | + $maxv = (1 << $toBits) - 1; | |
| 118 | 118 | $maxAcc = (1 << ($fromBits + $toBits - 1)) - 1; | 
| 119 | 119 | |
| 120 | 120 |          foreach ($data as $value) { | 
| @@ -100,10 +100,10 @@ discard block | ||
| 100 | 100 | */ | 
| 101 | 101 | private static function payToScriptHashSequence(array $cmds): bool | 
| 102 | 102 |      { | 
| 103 | - return 3 === \count($cmds) | |
| 103 | + return 3 === \count($cmds) | |
| 104 | 104 | && $cmds[0] === OpCodes::OP_HASH160->value | 
| 105 | 105 | && \is_string($cmds[1]) | 
| 106 | - && 20 === \strlen($cmds[1]) | |
| 106 | + && 20 === \strlen($cmds[1]) | |
| 107 | 107 | && $cmds[2] === OpCodes::OP_EQUAL->value; | 
| 108 | 108 | } | 
| 109 | 109 | |
| @@ -139,7 +139,7 @@ discard block | ||
| 139 | 139 | |
| 140 | 140 | private static function payToWitnessPubKeyHashSequence(array $stack): bool | 
| 141 | 141 |      { | 
| 142 | - return 2 === \count($stack) | |
| 142 | + return 2 === \count($stack) | |
| 143 | 143 | && $stack[0] === Encoding\StackNum::encode(0) | 
| 144 | 144 | && \is_string($stack[1]) | 
| 145 | 145 | && 20 === \strlen($stack[1]); | 
| @@ -147,7 +147,7 @@ discard block | ||
| 147 | 147 | |
| 148 | 148 | private static function payToWitnessScriptHashSequence(array $stack): bool | 
| 149 | 149 |      { | 
| 150 | - return 2 === \count($stack) | |
| 150 | + return 2 === \count($stack) | |
| 151 | 151 | && $stack[0] === Encoding\StackNum::encode(0) | 
| 152 | 152 | && \is_string($stack[1]) | 
| 153 | 153 | && 32 === \strlen($stack[1]); |