forked from Bit-Wasp/bitcoin-php
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathKeyToScriptDataFactory.php
More file actions
57 lines (48 loc) · 1.69 KB
/
KeyToScriptDataFactory.php
File metadata and controls
57 lines (48 loc) · 1.69 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
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace BitWasp\Bitcoin\Key\KeyToScript\Factory;
use BitWasp\Bitcoin\Crypto\EcAdapter\EcSerializer;
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\KeyInterface;
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PrivateKeyInterface;
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface;
use BitWasp\Bitcoin\Crypto\EcAdapter\Serializer\Key\PublicKeySerializerInterface;
use BitWasp\Bitcoin\Key\KeyToScript\ScriptAndSignData;
use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory;
abstract class KeyToScriptDataFactory extends ScriptDataFactory
{
/**
* @var PublicKeySerializerInterface
*/
protected $pubKeySerializer;
/**
* KeyToP2PKScriptFactory constructor.
* @param PublicKeySerializerInterface|null $pubKeySerializer
*/
public function __construct(?PublicKeySerializerInterface $pubKeySerializer = null)
{
if (null === $pubKeySerializer) {
$pubKeySerializer = EcSerializer::getSerializer(PublicKeySerializerInterface::class, true);
}
$this->pubKeySerializer = $pubKeySerializer;
}
/**
* @param PublicKeyInterface ...$keys
* @return ScriptAndSignData
*/
abstract protected function convertKeyToScriptData(PublicKeyInterface ...$keys): ScriptAndSignData;
/**
* @param KeyInterface ...$keys
* @return ScriptAndSignData
*/
public function convertKey(KeyInterface ...$keys): ScriptAndSignData
{
$pubs = [];
foreach ($keys as $key) {
if ($key instanceof PrivateKeyInterface) {
$key = $key->getPublicKey();
}
$pubs[] = $key;
}
return $this->convertKeyToScriptData(...$pubs);
}
}