1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Key\Deterministic\HdPrefix; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter; |
6
|
|
|
use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory; |
7
|
|
|
|
8
|
|
|
class ScriptPrefix |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private $privatePrefix; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $publicPrefix; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var ScriptDataFactory |
22
|
|
|
*/ |
23
|
|
|
private $scriptDataFactory; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* ScriptPrefixConfig constructor. |
27
|
|
|
* @param ScriptDataFactory $scriptDataFactory |
28
|
|
|
* @param string $privatePrefix |
29
|
|
|
* @param string $publicPrefix |
30
|
|
|
*/ |
31
|
13 |
|
public function __construct(ScriptDataFactory $scriptDataFactory, $privatePrefix, $publicPrefix) |
32
|
|
|
{ |
33
|
13 |
|
if (strlen($privatePrefix) !== 8) { |
34
|
1 |
|
throw new InvalidNetworkParameter("Invalid HD private prefix: wrong length"); |
35
|
|
|
} |
36
|
|
|
|
37
|
12 |
|
if (!ctype_xdigit($privatePrefix)) { |
38
|
1 |
|
throw new InvalidNetworkParameter("Invalid HD private prefix: expecting hex"); |
39
|
|
|
} |
40
|
|
|
|
41
|
11 |
|
if (strlen($publicPrefix) !== 8) { |
42
|
1 |
|
throw new InvalidNetworkParameter("Invalid HD public prefix: wrong length"); |
43
|
|
|
} |
44
|
|
|
|
45
|
10 |
|
if (!ctype_xdigit($publicPrefix)) { |
46
|
1 |
|
throw new InvalidNetworkParameter("Invalid HD public prefix: expecting hex"); |
47
|
|
|
} |
48
|
|
|
|
49
|
9 |
|
$this->scriptDataFactory = $scriptDataFactory; |
50
|
9 |
|
$this->publicPrefix = $publicPrefix; |
51
|
9 |
|
$this->privatePrefix = $privatePrefix; |
52
|
9 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
9 |
|
public function getPrivatePrefix() |
58
|
|
|
{ |
59
|
9 |
|
return $this->privatePrefix; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
9 |
|
public function getPublicPrefix() |
66
|
|
|
{ |
67
|
9 |
|
return $this->publicPrefix; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return ScriptDataFactory |
72
|
|
|
*/ |
73
|
9 |
|
public function getScriptDataFactory() |
74
|
|
|
{ |
75
|
9 |
|
return $this->scriptDataFactory; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|