|
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
|
50 |
|
public function __construct(ScriptDataFactory $scriptDataFactory, $privatePrefix, $publicPrefix) |
|
32
|
|
|
{ |
|
33
|
50 |
|
if (strlen($privatePrefix) !== 8) { |
|
34
|
1 |
|
throw new InvalidNetworkParameter("Invalid HD private prefix: wrong length"); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
49 |
|
if (!ctype_xdigit($privatePrefix)) { |
|
38
|
1 |
|
throw new InvalidNetworkParameter("Invalid HD private prefix: expecting hex"); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
48 |
|
if (strlen($publicPrefix) !== 8) { |
|
42
|
1 |
|
throw new InvalidNetworkParameter("Invalid HD public prefix: wrong length"); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
47 |
|
if (!ctype_xdigit($publicPrefix)) { |
|
46
|
1 |
|
throw new InvalidNetworkParameter("Invalid HD public prefix: expecting hex"); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
46 |
|
$this->scriptDataFactory = $scriptDataFactory; |
|
50
|
46 |
|
$this->publicPrefix = $publicPrefix; |
|
51
|
46 |
|
$this->privatePrefix = $privatePrefix; |
|
52
|
46 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
45 |
|
public function getPrivatePrefix() |
|
58
|
|
|
{ |
|
59
|
45 |
|
return $this->privatePrefix; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
45 |
|
public function getPublicPrefix() |
|
66
|
|
|
{ |
|
67
|
45 |
|
return $this->publicPrefix; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return ScriptDataFactory |
|
72
|
|
|
*/ |
|
73
|
54 |
|
public function getScriptDataFactory() |
|
74
|
|
|
{ |
|
75
|
54 |
|
return $this->scriptDataFactory; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|