Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] update CBOR to make compatible with Laravel 10 #28

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"php": "^8.2",
"ext-gmp": "*",
"ext-bcmath": "*",
"laravel/framework": ">=v7.0.0",
"spomky-labs/cbor-php": "2.0.0"
"laravel/framework": ">=v7.0.0|>=v10.0.0",
"spomky-labs/cbor-php": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "~8.0"
Expand Down
19 changes: 12 additions & 7 deletions src/Drivers/CborDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CBOR\TAg;
use CBOR\StringStream;
use CBOR\OtherObject;
use CBOR\Tag\GenericTag;
use Illuminate\Support\Str;
use Merkeleon\PhpCryptocurrencyAddressValidation\Utils\Base58Decoder;
use Throwable;
Expand All @@ -25,10 +26,10 @@ public function __construct(array $options)
parent::__construct($options);

$otherObjectManager = new OtherObject\OtherObjectManager();
$tagManager = new Tag\TagObjectManager();

$otherObjectManager->add(OtherObject\SimpleObject::class);
$tagManager->add(Tag\PositiveBigIntegerTag::class);

$tagManager = new Tag\TagManager();
$tagManager->add(Tag\UnsignedBigIntegerTag::class);

$this->decoder = new Decoder($tagManager, $otherObjectManager);
}
Expand All @@ -54,24 +55,28 @@ public function check(string $address): bool
return false;
}

$normalizedData = $object->getNormalizedData();
/** @var array $normalizedData */
$normalizedData = $object->normalize();

if (count($normalizedData) !== 2) {
return false;
}
if (!is_numeric($normalizedData[1])) {
return false;
}
if (!$normalizedData[0] instanceof ByteStringObject) {

if (!$normalizedData[0] instanceof GenericTag) {
return false;
}

$bs = $normalizedData[0];
/** @var ByteStringObject $bs */
$bs = $normalizedData[0]->getValue();

if (!in_array($bs->getLength(), array_values($this->options), true)) {
return false;
}

$crcCalculated = crc32($normalizedData[0]->getValue());
$crcCalculated = crc32($bs->getValue());
$validCrc = $normalizedData[1];

return $crcCalculated === (int)$validCrc;
Expand Down
1 change: 0 additions & 1 deletion tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function currencyAddressProvider(): array
'Cardano #3' => [CurrencyEnum::CARDANO, 'mainnet', true, 'addr1qxy3w62dupy9pzmpdfzxz4k240w5vawyagl5m9djqquyymrtm3grn7gpnjh7rwh2dy62hk8639lt6kzn32yxq960usnq9pexvt'],
'Cardano #4' => [CurrencyEnum::CARDANO, 'mainnet', true, 'Ae2tdPwUPEYwNguM7TB3dMnZMfZxn1pjGHyGdjaF4mFqZF9L3bj6cdhiH8t'],
'Cardano #5' => [CurrencyEnum::CARDANO, 'mainnet', true, 'DdzFFzCqrht2KYLcX8Vu53urCG52NxpgrGQvP9Mcp15Q8BkB9df9GndFDBRjoWTPuNkLW3yeQiFVet1KA7mraEkJ84AK2RwcEh3khs12'],

'Cardano #6' => [CurrencyEnum::CARDANO, 'testnet', true, '37btjrVyb4KBbrmcxh3qQzswqDB4SCU8L68vYBJshaeYQ8rHVBfrAfuXZNyFHtR8QXUKR4CtytMyX4DwhsPYKKgFSpq8f5KxNz2s6Guqr6c6LzcHck'],
'Cardano #7' => [CurrencyEnum::CARDANO, 'testnet', true, '2cWKMJemoBaipAW1NGegM2qWevSgpL9baiizayY4NnTBvxRGyppr2uym7F9eEtRLehFek'],
'Cardano #8' => [CurrencyEnum::CARDANO, 'testnet', true, 'addr_test1qzfst6x8f4r47vm4qfeuj7g8r5pgkjnv5cuzjk94u8p7sd3gtlpjssk2fy95k4z5lr48tu48fcqstnzte44d8f8v8vhs9pwu4x'],
Expand Down