From c35caa065496c545e6817e98f254909c85d3fe01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Tue, 10 Jun 2025 19:26:04 +0200 Subject: [PATCH] Remove obsolete bech32 decoder --- config/packages/doctrine.yaml | 2 +- src/Util/Bech32/Bech32Decoder.php | 154 ------------------------------ 2 files changed, 1 insertion(+), 155 deletions(-) delete mode 100644 src/Util/Bech32/Bech32Decoder.php diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 9d1f84c..22ccf54 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -37,7 +37,7 @@ when@test: doctrine: dbal: # "TEST_TOKEN" is typically set by ParaTest - dbname_suffix: '_test%env(default::TEST_TOKEN)%' + dbname_suffix: '' when@prod: doctrine: diff --git a/src/Util/Bech32/Bech32Decoder.php b/src/Util/Bech32/Bech32Decoder.php deleted file mode 100644 index 7205633..0000000 --- a/src/Util/Bech32/Bech32Decoder.php +++ /dev/null @@ -1,154 +0,0 @@ -> $fromBits) { - throw new Exception('Invalid value in data'); - } - $acc = (($acc << $fromBits) | $value) & $max_acc; - $bits += $fromBits; - while ($bits >= $toBits) { - $bits -= $toBits; - $ret[] = ($acc >> $bits) & $maxv; - } - } - - if ($pad) { - if ($bits > 0) { - $ret[] = ($acc << ($toBits - $bits)) & $maxv; - } - } else if ($bits >= $fromBits || (($acc << ($toBits - $bits)) & $maxv)) { - throw new Exception('Invalid padding'); - } - - return $ret; - } - - // Public method to decode a Nostr Bech32 string and return hex - public function decodeNostrBech32ToHex(string $bech32): string - { - list($hrp, $data) = $this->decodeBech32($bech32); - - // Convert 5-bit data back to 8-bit data - $decodedData = $this->convertBits($data, 5, 8, false); - - // Return the decoded data as a hex string - return bin2hex(pack('C*', ...$decodedData)); - } - - // Public method to decode a Nostr Bech32 string and return the binary data - - /** - * @throws Exception - */ - public function decodeNostrBech32ToBinary(string $bech32): array - { - list($hrp, $data) = $this->decodeBech32($bech32); - - // Convert 5-bit data to 8-bit data - $decodedData = $this->convertBits($data, 5, 8); - - return [$hrp, $decodedData]; - } - - // Public method to parse the binary data into TLV format - public function parseTLV(array $binaryData): array - { - $parsedTLVs = []; - $offset = 0; - - while ($offset < count($binaryData)) { - if ($offset + 1 >= count($binaryData)) { - throw new Exception("Incomplete TLV data"); - } - - // Read the Type (T) and Length (L) - $type = $binaryData[$offset]; - $length = $binaryData[$offset + 1]; - $offset += 2; - - // Ensure we have enough data for the value - if ($offset + $length > count($binaryData)) { - break; - } else { - // Extract the Value (V) - $value = array_slice($binaryData, $offset, $length); - } - - $offset += $length; - - // Add the TLV to the parsed array - $parsedTLVs[] = [ - 'type' => $type, - 'length' => $length, - 'value' => $value, - ]; - } - - return $parsedTLVs; - } - - // Decode and parse a Bech32 string - - /** - * @throws Exception - */ - public function decodeAndParseNostrBech32(string $bech32): array - { - // Step 1: Decode Bech32 to binary data - list($hrp, $binaryData) = $this->decodeNostrBech32ToBinary($bech32); - - if ($hrp == 'npub') { - return [$hrp, $binaryData]; - } - - // Step 2: Parse the binary data into TLV format - $tlvData = $this->parseTLV($binaryData); - - return [$hrp, $tlvData]; - } -}