@@ -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::encodeStackNum(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::encodeStackNum(0) |
152 | 152 | && \is_string($stack[1]) |
153 | 153 | && 32 === \strlen($stack[1]); |
@@ -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]); |
@@ -54,8 +54,7 @@ discard block |
||
54 | 54 | rewind($stream); |
55 | 55 | |
56 | 56 | return $segwit ? |
57 | - self::parseSegWit($stream, $testnet) : |
|
58 | - self::parseLegacy($stream, $testnet); |
|
57 | + self::parseSegWit($stream, $testnet) : self::parseLegacy($stream, $testnet); |
|
59 | 58 | } |
60 | 59 | |
61 | 60 | public function serialize(): string |
@@ -74,8 +73,7 @@ discard block |
||
74 | 73 | $witness .= Encoding::encodeVarInt(\count($txIn->witness)); |
75 | 74 | foreach ($txIn->witness as $element) { |
76 | 75 | $witness .= \is_int($element) ? |
77 | - Encoding::toLE(gmp_init($element)) : |
|
78 | - Encoding::encodeVarInt(\strlen($element)).$element; |
|
76 | + Encoding::toLE(gmp_init($element)) : Encoding::encodeVarInt(\strlen($element)).$element; |
|
79 | 77 | } |
80 | 78 | } |
81 | 79 | } |
@@ -92,12 +90,12 @@ discard block |
||
92 | 90 | |
93 | 91 | public function isCoinbase(): bool |
94 | 92 | { |
95 | - return 1 === \count($this->txIns) |
|
93 | + return 1 === \count($this->txIns) |
|
96 | 94 | && '0000000000000000000000000000000000000000000000000000000000000000' === $this->txIns[0]->prevTxId |
97 | - && 0xFFFFFFFF === $this->txIns[0]->prevIndex; |
|
95 | + && 0xFFFFFFFF === $this->txIns[0]->prevIndex; |
|
98 | 96 | } |
99 | 97 | |
100 | - public function blockHeight(): int|false |
|
98 | + public function blockHeight(): int | false |
|
101 | 99 | { |
102 | 100 | if (!$this->isCoinbase()) { |
103 | 101 | return false; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | return new static($x, $y); |
65 | 65 | } |
66 | 66 | |
67 | - public function scalarMul(\GMP|int $coefficient): self |
|
67 | + public function scalarMul(\GMP | int $coefficient): self |
|
68 | 68 | { |
69 | 69 | // Optimization: reduce the coefficient modulo N before computing the multiplication |
70 | 70 | $c = $coefficient % S256Params::N(); |
@@ -124,8 +124,7 @@ discard block |
||
124 | 124 | $beta = $alpha->sqrt(); |
125 | 125 | |
126 | 126 | return "\x02" === $sec[0] ? |
127 | - new self($x, (0 == $beta->num % 2) ? $beta : new S256Field(S256Params::P() - $beta->num)) : |
|
128 | - new self($x, (0 == $beta->num % 2) ? new S256Field(S256Params::P() - $beta->num) : $beta); |
|
127 | + 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); |
|
129 | 128 | } |
130 | 129 | |
131 | 130 | public function address(bool $compressed = true, bool $testnet = true): string |
@@ -148,7 +147,7 @@ discard block |
||
148 | 147 | { |
149 | 148 | $sInv = gmp_powm($sig->s, S256Params::N() - 2, S256Params::N()); |
150 | 149 | |
151 | - $u = ($z * $sInv) % S256Params::N(); |
|
150 | + $u = ($z * $sInv) % S256Params::N(); |
|
152 | 151 | $v = ($sig->r * $sInv) % S256Params::N(); |
153 | 152 | |
154 | 153 | $R = S256Params::G()->scalarMul($u)->add($this->scalarMul($v)); |
@@ -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 | } |