Skip to content

Commit 8895aae

Browse files
authored
Merge pull request #3 from androzd/master
DOGE validator
2 parents a1b781a + 747bc15 commit 8895aae

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Validation/DOGE.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
4+
5+
6+
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
7+
8+
class DOGE extends Validation
9+
{
10+
11+
public function validate($address)
12+
{
13+
$address = hex2bin(self::base58ToHex($address));
14+
if (strlen($address) !== 25)
15+
{
16+
return false;
17+
}
18+
$checksum = substr($address, 21, 4);
19+
$rawAddress = substr($address, 0, 21);
20+
if (substr(hex2bin(hash('sha256', hex2bin(hash('sha256', $rawAddress)))), 0, 4) === $checksum)
21+
{
22+
return true;
23+
}
24+
else
25+
{
26+
return false;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)