forked from Bit-Wasp/bitcoin-php
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathPublicKeyFactory.php
More file actions
50 lines (43 loc) · 1.32 KB
/
PublicKeyFactory.php
File metadata and controls
50 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace BitWasp\Bitcoin\Key\Factory;
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Crypto\EcAdapter\Adapter\EcAdapterInterface;
use BitWasp\Bitcoin\Crypto\EcAdapter\EcSerializer;
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface;
use BitWasp\Bitcoin\Crypto\EcAdapter\Serializer\Key\PublicKeySerializerInterface;
use BitWasp\Buffertools\Buffer;
use BitWasp\Buffertools\BufferInterface;
class PublicKeyFactory
{
/**
* @var PublicKeySerializerInterface
*/
private $serializer;
/**
* PublicKeyFactory constructor.
* @param EcAdapterInterface $ecAdapter
*/
public function __construct(?EcAdapterInterface $ecAdapter = null)
{
$ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
$this->serializer = EcSerializer::getSerializer(PublicKeySerializerInterface::class, true, $ecAdapter);
}
/**
* @param string $hex
* @return PublicKeyInterface
* @throws \Exception
*/
public function fromHex(string $hex): PublicKeyInterface
{
return $this->fromBuffer(Buffer::hex($hex));
}
/**
* @param BufferInterface $buffer
* @return PublicKeyInterface
*/
public function fromBuffer(BufferInterface $buffer): PublicKeyInterface
{
return $this->serializer->parse($buffer);
}
}