@@ -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]); |
@@ -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 | } |
@@ -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::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 | } |
@@ -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; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | return new static($x, $y); |
71 | 71 | } |
72 | 72 | |
73 | - public function scalarMul(\GMP|int $coefficient): self |
|
73 | + public function scalarMul(\GMP | int $coefficient): self |
|
74 | 74 | { |
75 | 75 | // Optimization: reduce the coefficient modulo N before computing the multiplication |
76 | 76 | $c = $coefficient % S256Params::N(); |
@@ -114,8 +114,7 @@ discard block |
||
114 | 114 | $beta = $alpha->sqrt(); |
115 | 115 | |
116 | 116 | return "\x02" === $sec[0] ? |
117 | - new self($x, (0 == $beta->num % 2) ? $beta : new S256Field(S256Params::P() - $beta->num)) : |
|
118 | - new self($x, (0 == $beta->num % 2) ? new S256Field(S256Params::P() - $beta->num) : $beta); |
|
117 | + 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); |
|
119 | 118 | } |
120 | 119 | |
121 | 120 | public function address(bool $compressed = true, Network $mode = Network::TESTNET): string |
@@ -138,7 +137,7 @@ discard block |
||
138 | 137 | { |
139 | 138 | $sInv = gmp_powm($sig->s, S256Params::N() - 2, S256Params::N()); |
140 | 139 | |
141 | - $u = ($z * $sInv) % S256Params::N(); |
|
140 | + $u = ($z * $sInv) % S256Params::N(); |
|
142 | 141 | $v = ($sig->r * $sInv) % S256Params::N(); |
143 | 142 | |
144 | 143 | $R = S256Params::G()->scalarMul($u)->add($this->scalarMul($v)); |
@@ -16,9 +16,9 @@ |
||
16 | 16 | public string $parentFingerprint; |
17 | 17 | public int $childNumber; |
18 | 18 | public string $chainCode; |
19 | - public PrivateKey|S256Point $key; |
|
19 | + public PrivateKey | S256Point $key; |
|
20 | 20 | |
21 | - public function __construct(Version $version, int $depth, string $parentFingerprint, int $childNumber, string $chainCode, PrivateKey|S256Point $key) |
|
21 | + public function __construct(Version $version, int $depth, string $parentFingerprint, int $childNumber, string $chainCode, PrivateKey | S256Point $key) |
|
22 | 22 | { |
23 | 23 | if (0 === $depth && '00000000' !== $parentFingerprint) { |
24 | 24 | throw new \InvalidArgumentException('An extended key of depth 0 cannot have a parent fingerprint'); |
@@ -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; |