1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BitWasp\Bitcoin\Key\KeyToScript\Factory; |
6
|
|
|
|
7
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\EcSerializer; |
8
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\KeyInterface; |
9
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PrivateKeyInterface; |
10
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface; |
11
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\Serializer\Key\PublicKeySerializerInterface; |
12
|
|
|
use BitWasp\Bitcoin\Key\KeyToScript\ScriptAndSignData; |
13
|
|
|
use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory; |
14
|
|
|
|
15
|
|
|
abstract class KeyToScriptDataFactory extends ScriptDataFactory |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var PublicKeySerializerInterface |
19
|
|
|
*/ |
20
|
|
|
protected $pubKeySerializer; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* KeyToP2PKScriptFactory constructor. |
24
|
|
|
* @param PublicKeySerializerInterface|null $pubKeySerializer |
25
|
|
|
*/ |
26
|
108 |
|
public function __construct(PublicKeySerializerInterface $pubKeySerializer = null) |
27
|
|
|
{ |
28
|
108 |
|
if (null === $pubKeySerializer) { |
29
|
85 |
|
$pubKeySerializer = EcSerializer::getSerializer(PublicKeySerializerInterface::class, true); |
30
|
|
|
} |
31
|
|
|
|
32
|
108 |
|
$this->pubKeySerializer = $pubKeySerializer; |
33
|
108 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param PublicKeyInterface $publicKey |
37
|
|
|
* @return ScriptAndSignData |
38
|
|
|
*/ |
39
|
|
|
abstract protected function convertKeyToScriptData(PublicKeyInterface $publicKey): ScriptAndSignData; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param KeyInterface $key |
43
|
|
|
* @return ScriptAndSignData |
44
|
|
|
*/ |
45
|
32 |
|
public function convertKey(KeyInterface $key): ScriptAndSignData |
46
|
|
|
{ |
47
|
32 |
|
if ($key->isPrivate()) { |
48
|
|
|
/** @var PrivateKeyInterface $key */ |
49
|
23 |
|
$key = $key->getPublicKey(); |
50
|
|
|
} |
51
|
|
|
/** @var PublicKeyInterface $key */ |
52
|
32 |
|
return $this->convertKeyToScriptData($key); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|