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\Exceptions\NotImplementedException; |
9
|
|
|
use BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix; |
10
|
|
|
use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory; |
11
|
|
|
use BitWasp\Bitcoin\Key\KeyToScript\KeyToScriptHelper; |
12
|
|
|
|
13
|
|
|
class Slip132 |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var KeyToScriptHelper |
17
|
|
|
*/ |
18
|
|
|
private $helper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Slip132PrefixRegistry constructor. |
22
|
|
|
|
23
|
|
|
* @param KeyToScriptHelper $helper |
24
|
|
|
*/ |
25
|
20 |
|
public function __construct(KeyToScriptHelper $helper = null) |
26
|
|
|
{ |
27
|
20 |
|
$this->helper = $helper ?: new KeyToScriptHelper(Bitcoin::getEcAdapter()); |
28
|
20 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param PrefixRegistry $registry |
32
|
|
|
* @param ScriptDataFactory $factory |
33
|
|
|
* @return ScriptPrefix |
34
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
35
|
|
|
*/ |
36
|
16 |
|
private function loadPrefix(PrefixRegistry $registry, ScriptDataFactory $factory): ScriptPrefix |
37
|
|
|
{ |
38
|
16 |
|
list ($private, $public) = $registry->getPrefixes($factory->getScriptType()); |
39
|
16 |
|
return new ScriptPrefix($factory, $private, $public); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* xpub on bitcoin |
44
|
|
|
* @param PrefixRegistry $registry |
45
|
|
|
* @return ScriptPrefix |
46
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
47
|
|
|
*/ |
48
|
6 |
|
public function p2pkh(PrefixRegistry $registry): ScriptPrefix |
49
|
|
|
{ |
50
|
6 |
|
return $this->loadPrefix($registry, $this->helper->getP2pkhFactory()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* ypub on bitcoin |
55
|
|
|
* @param PrefixRegistry $registry |
56
|
|
|
* @return ScriptPrefix |
57
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException |
58
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
59
|
|
|
*/ |
60
|
4 |
|
public function p2shP2wpkh(PrefixRegistry $registry): ScriptPrefix |
61
|
|
|
{ |
62
|
4 |
|
return $this->loadPrefix($registry, $this->helper->getP2shFactory($this->helper->getP2wpkhFactory())); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Ypub on bitcoin |
67
|
|
|
* @param PrefixRegistry $registry |
68
|
|
|
* @return ScriptPrefix |
69
|
|
|
* @throws NotImplementedException |
70
|
|
|
*/ |
71
|
2 |
|
public function p2shP2wshP2pkh(PrefixRegistry $registry): ScriptPrefix |
|
|
|
|
72
|
|
|
{ |
73
|
2 |
|
throw new NotImplementedException("Ypub/prv not supported yet"); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Ypub on bitcoin |
78
|
|
|
* @param int $m |
79
|
|
|
* @param int $n |
80
|
|
|
* @param bool $sortKeys |
81
|
|
|
* @param PrefixRegistry $registry |
82
|
|
|
* @return ScriptPrefix |
83
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException |
84
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
85
|
|
|
*/ |
86
|
|
|
public function p2shP2wshMultisig(int $m, int $n, bool $sortKeys, PrefixRegistry $registry): ScriptPrefix |
87
|
|
|
{ |
88
|
|
|
return $this->loadPrefix($registry, $this->helper->getP2shP2wshFactory($this->helper->getMultisigFactory($m, $n, $sortKeys))); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* zpub on bitcoin |
93
|
|
|
* @param PrefixRegistry $registry |
94
|
|
|
* @return ScriptPrefix |
95
|
|
|
* @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter |
96
|
|
|
*/ |
97
|
6 |
|
public function p2wpkh(PrefixRegistry $registry): ScriptPrefix |
98
|
|
|
{ |
99
|
6 |
|
return $this->loadPrefix($registry, $this->helper->getP2wpkhFactory()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Zpub on bitcoin |
104
|
|
|
* @param PrefixRegistry $registry |
105
|
|
|
* @return ScriptPrefix |
106
|
|
|
* @throws NotImplementedException |
107
|
|
|
*/ |
108
|
2 |
|
public function p2wshP2pkh(PrefixRegistry $registry): ScriptPrefix |
|
|
|
|
109
|
|
|
{ |
110
|
2 |
|
throw new NotImplementedException("Zpub/prv not supported yet"); |
111
|
|
|
} |
112
|
|
|
/** |
113
|
|
|
* Zpub on bitcoin |
114
|
|
|
* @param PrefixRegistry $registry |
115
|
|
|
* @return ScriptPrefix |
116
|
|
|
* @throws NotImplementedException |
117
|
|
|
*/ |
118
|
|
|
public function p2wshMultisig(int $m, int $n, bool $sortKeys, PrefixRegistry $registry): ScriptPrefix |
119
|
|
|
{ |
120
|
|
|
return $this->loadPrefix($registry, $this->helper->getP2wshFactory($this->helper->getMultisigFactory($m, $n, $sortKeys))); |
121
|
|
|
throw new NotImplementedException("Zpub/prv not supported yet"); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.