Skip to content

Commit

Permalink
Merge pull request #35 from LiquidCats/feature/add-bech32m-addresses-…
Browse files Browse the repository at this point in the history
…support
  • Loading branch information
androzd authored Nov 6, 2023
2 parents 4f54897 + 25e3538 commit a014b76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Utils/Bech32Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ class Bech32Decoder
-1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1,
1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1
];

public const BECH32_POLY = 1;
public const BECH32M_POLY = 0x2bc830a3;
private const ALLOWED_POLY = [
self::BECH32_POLY,
self::BECH32M_POLY,
];
/**
* Validates a bech32 string and returns [$hrp, $dataChars] if
* the conversion was successful. An exception is thrown on invalid
Expand Down Expand Up @@ -139,7 +144,7 @@ private function verifyChecksum(string $hrp, array $convertedDataChars): bool
$r = array_merge($expandHrp, $convertedDataChars);
$poly = $this->polyMod($r, count($r));

return $poly === 1;
return in_array($poly, self::ALLOWED_POLY, true);
}


Expand Down
1 change: 1 addition & 0 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function currencyAddressProvider(): array
'Bitcoin #6' => [CurrencyEnum::BITCOIN, 'testnet', false, '1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2'],
'Bitcoin #7' => [CurrencyEnum::BITCOIN, 'testnet', false, 'bc1q6v096h88xmpl662af0nc7wd3vta56zv6pyccl8'],
'Bitcoin #8' => [CurrencyEnum::BITCOIN, 'mainnet', true, 'BC1QL2725QLXHGWQ7F7XLJ8363FJCUF25XZ35SWRU5'],
'Bitcoin #9' => [CurrencyEnum::BITCOIN, 'mainnet', true, 'bc1p5gyty9x2lrk65yndaeh242zm6xklgrv9nze9477dg0kyv6yvfljq0lqjkh'],
//
'Cardano #1' => [CurrencyEnum::CARDANO, 'mainnet', true, 'addr1v9ywm0h3r8cnxrs04gfy7c3s2j44utjyvn5ldjdca0c2ltccgqdes'],
'Cardano #2' => [CurrencyEnum::CARDANO, 'mainnet', false, 'stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz'],
Expand Down

0 comments on commit a014b76

Please sign in to comment.