@@ -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; |
@@ -119,10 +119,10 @@ |
||
119 | 119 | |
120 | 120 | public function isP2SH(): bool |
121 | 121 | { |
122 | - return 3 === \count($this->cmds) |
|
122 | + return 3 === \count($this->cmds) |
|
123 | 123 | && $this->cmds[0] === OpCodes::OP_HASH160->value |
124 | 124 | && \is_string($this->cmds[1]) |
125 | - && 20 === \strlen($this->cmds[1]) |
|
125 | + && 20 === \strlen($this->cmds[1]) |
|
126 | 126 | && $this->cmds[2] === OpCodes::OP_EQUAL->value; |
127 | 127 | } |
128 | 128 |
@@ -81,10 +81,10 @@ |
||
81 | 81 | */ |
82 | 82 | private static function payToScriptHashSequence(array $cmds): bool |
83 | 83 | { |
84 | - return 3 === \count($cmds) |
|
84 | + return 3 === \count($cmds) |
|
85 | 85 | && $cmds[0] === OpCodes::OP_HASH160->value |
86 | 86 | && \is_string($cmds[1]) |
87 | - && 20 === \strlen($cmds[1]) |
|
87 | + && 20 === \strlen($cmds[1]) |
|
88 | 88 | && $cmds[2] === OpCodes::OP_EQUAL->value; |
89 | 89 | } |
90 | 90 |
@@ -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 | } |