1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BitWasp\Bitcoin\Key\Deterministic\Slip132; |
6
|
|
|
|
7
|
|
|
use BitWasp\Bitcoin\Bitcoin; |
8
|
|
|
use BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix; |
9
|
|
|
use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory; |
10
|
|
|
use BitWasp\Bitcoin\Key\KeyToScript\KeyToScriptHelper; |
11
|
|
|
|
12
|
|
|
class Slip132 |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var KeyToScriptHelper |
16
|
|
|
*/ |
17
|
|
|
private $helper; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Slip132PrefixRegistry constructor. |
21
|
|
|
|
22
|
|
|
* @param KeyToScriptHelper $helper |
23
|
|
|
*/ |
24
|
22 |
|
public function __construct(KeyToScriptHelper $helper = null) |
25
|
|
|
{ |
26
|
22 |
|
$this->helper = $helper ?: new KeyToScriptHelper(Bitcoin::getEcAdapter()); |
27
|
22 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param PrefixRegistry $registry |
31
|
|
|
* @param ScriptDataFactory $factory |
32
|
|
|
* @return ScriptPrefix |
33
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
34
|
|
|
*/ |
35
|
22 |
|
private function loadPrefix(PrefixRegistry $registry, ScriptDataFactory $factory): ScriptPrefix |
36
|
|
|
{ |
37
|
22 |
|
list ($private, $public) = $registry->getPrefixes($factory->getScriptType()); |
38
|
22 |
|
return new ScriptPrefix($factory, $private, $public); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* xpub on bitcoin |
43
|
|
|
* @param PrefixRegistry $registry |
44
|
|
|
* @return ScriptPrefix |
45
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
46
|
|
|
*/ |
47
|
6 |
|
public function p2pkh(PrefixRegistry $registry): ScriptPrefix |
48
|
|
|
{ |
49
|
6 |
|
return $this->loadPrefix($registry, $this->helper->getP2pkhFactory()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* xpub on bitcoin |
54
|
|
|
* @param PrefixRegistry $registry |
55
|
|
|
* @return ScriptPrefix |
56
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException |
57
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
58
|
|
|
*/ |
59
|
2 |
|
public function p2shP2pkh(PrefixRegistry $registry): ScriptPrefix |
60
|
|
|
{ |
61
|
2 |
|
return $this->loadPrefix($registry, $this->helper->getP2shFactory($this->helper->getP2pkhFactory())); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* ypub on bitcoin |
66
|
|
|
* @param PrefixRegistry $registry |
67
|
|
|
* @return ScriptPrefix |
68
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException |
69
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
70
|
|
|
*/ |
71
|
4 |
|
public function p2shP2wpkh(PrefixRegistry $registry): ScriptPrefix |
72
|
|
|
{ |
73
|
4 |
|
return $this->loadPrefix($registry, $this->helper->getP2shFactory($this->helper->getP2wpkhFactory())); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Ypub on bitcoin |
78
|
|
|
* @param PrefixRegistry $registry |
79
|
|
|
* @return ScriptPrefix |
80
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException |
81
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
82
|
|
|
*/ |
83
|
2 |
|
public function p2shP2wshP2pkh(PrefixRegistry $registry): ScriptPrefix |
84
|
|
|
{ |
85
|
2 |
|
return $this->loadPrefix($registry, $this->helper->getP2shP2wshFactory($this->helper->getP2pkhFactory())); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* zpub on bitcoin |
90
|
|
|
* @param PrefixRegistry $registry |
91
|
|
|
* @return ScriptPrefix |
92
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
93
|
|
|
*/ |
94
|
6 |
|
public function p2wpkh(PrefixRegistry $registry): ScriptPrefix |
95
|
|
|
{ |
96
|
6 |
|
return $this->loadPrefix($registry, $this->helper->getP2wpkhFactory()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Zpub on bitcoin |
101
|
|
|
* @param PrefixRegistry $registry |
102
|
|
|
* @return ScriptPrefix |
103
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException |
104
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
105
|
|
|
*/ |
106
|
2 |
|
public function p2wshP2pkh(PrefixRegistry $registry): ScriptPrefix |
107
|
|
|
{ |
108
|
2 |
|
return $this->loadPrefix($registry, $this->helper->getP2wshFactory($this->helper->getP2pkhFactory())); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|