@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | public \GMP $num; |
10 | 10 | public \GMP $order; |
11 | 11 | |
12 | - public function __construct(\GMP|int $number, \GMP|int $order) |
|
12 | + public function __construct(\GMP | int $number, \GMP | int $order) |
|
13 | 13 | { |
14 | 14 | if ($number < 0 || $order <= $number) { |
15 | 15 | throw new \InvalidArgumentException("$number not in field range [0, $order)"); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | return new static(($this->num * gmp_powm($divisor->num, $this->order - 2, $this->order)) % $this->order, $this->order); |
52 | 52 | } |
53 | 53 | |
54 | - public function exp(\GMP|int $exponent): static |
|
54 | + public function exp(\GMP | int $exponent): static |
|
55 | 55 | { |
56 | 56 | return new static(gmp_powm($this->num, $exponent % ($this->order - 1), $this->order), $this->order); |
57 | 57 | } |
@@ -9,12 +9,11 @@ |
||
9 | 9 | */ |
10 | 10 | final readonly class S256Field extends FieldElement |
11 | 11 | { |
12 | - public function __construct(\GMP|int|string $number) |
|
12 | + public function __construct(\GMP | int | string $number) |
|
13 | 13 | { |
14 | 14 | if (\is_string($number)) { |
15 | 15 | $number = str_starts_with($number, '0x') ? |
16 | - gmp_init($number) : |
|
17 | - gmp_import($number); |
|
16 | + gmp_init($number) : gmp_import($number); |
|
18 | 17 | } |
19 | 18 | |
20 | 19 | parent::__construct($number, S256Params::P()); |
@@ -38,8 +38,7 @@ discard block |
||
38 | 38 | $beta = $alpha->sqrt(); |
39 | 39 | |
40 | 40 | return "\x02" === $sec[0] ? |
41 | - new self($x, (0 == $beta->num % 2) ? $beta : new S256Field(S256Params::P() - $beta->num)) : |
|
42 | - new self($x, (0 == $beta->num % 2) ? new S256Field(S256Params::P() - $beta->num) : $beta); |
|
41 | + 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); |
|
43 | 42 | } |
44 | 43 | |
45 | 44 | public function address(bool $compressed = true, bool $testnet = true): string |
@@ -64,7 +63,7 @@ discard block |
||
64 | 63 | { |
65 | 64 | $sInv = gmp_powm($sig->s, S256Params::N() - 2, S256Params::N()); |
66 | 65 | |
67 | - $u = ($z * $sInv) % S256Params::N(); |
|
66 | + $u = ($z * $sInv) % S256Params::N(); |
|
68 | 67 | $v = ($sig->r * $sInv) % S256Params::N(); |
69 | 68 | |
70 | 69 | $R = S256Params::G()->scalarMul($u)->add($this->scalarMul($v)); |
@@ -72,7 +71,7 @@ discard block |
||
72 | 71 | return $R->x->num == $sig->r; |
73 | 72 | } |
74 | 73 | |
75 | - public function scalarMul(\GMP|int $coefficient): static |
|
74 | + public function scalarMul(\GMP | int $coefficient): static |
|
76 | 75 | { |
77 | 76 | // Optimization: reduce the coefficient before computing the multiplication |
78 | 77 | return parent::scalarMul($coefficient % S256Params::N()); |
@@ -71,7 +71,7 @@ |
||
71 | 71 | return new static($x, $y, $this->a, $this->b); |
72 | 72 | } |
73 | 73 | |
74 | - public function scalarMul(\GMP|int $coefficient): static |
|
74 | + public function scalarMul(\GMP | int $coefficient): static |
|
75 | 75 | { |
76 | 76 | $c = $coefficient instanceof \GMP ? $coefficient : gmp_init($coefficient); |
77 | 77 | $current = clone $this; |
@@ -50,8 +50,7 @@ discard block |
||
50 | 50 | rewind($stream); |
51 | 51 | |
52 | 52 | return $segwit ? |
53 | - self::parseSegWit($stream, $testnet) : |
|
54 | - self::parseLegacy($stream, $testnet); |
|
53 | + self::parseSegWit($stream, $testnet) : self::parseLegacy($stream, $testnet); |
|
55 | 54 | } |
56 | 55 | |
57 | 56 | public function serialize(): string |
@@ -70,8 +69,7 @@ discard block |
||
70 | 69 | $witness .= Encoding::encodeVarInt(\count($txIn->witness)); |
71 | 70 | foreach ($txIn->witness as $element) { |
72 | 71 | $witness .= \is_int($element) ? |
73 | - Encoding::toLE(gmp_init($element)) : |
|
74 | - Encoding::encodeVarInt(\strlen($element)).$element; |
|
72 | + Encoding::toLE(gmp_init($element)) : Encoding::encodeVarInt(\strlen($element)).$element; |
|
75 | 73 | } |
76 | 74 | } |
77 | 75 | } |
@@ -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]); |