Completed
Pull Request — 0.0.35 (#660)
by thomas
25:11
created

Slip132   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 82
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 5

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A loadPrefix() 0 5 1
A xpubP2pkh() 0 4 1
A ypubP2shP2wpkh() 0 4 1
A ypubP2shP2wshP2pkh() 0 4 1
A zpubP2wpkh() 0 4 1
A zpubP2wshP2pkh() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Key\Deterministic\Slip132;
4
5
use BitWasp\Bitcoin\Bitcoin;
6
use BitWasp\Bitcoin\Key\Deterministic\Slip132\PrefixRegistry;
7
use BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix;
8
use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory;
9
use BitWasp\Bitcoin\Key\KeyToScript\KeyToScriptHelper;
10
11
class Slip132
12
{
13
    /**
14
     * @var KeyToScriptHelper
15
     */
16
    private $helper;
17
18
    /**
19
     * Slip132PrefixRegistry constructor.
20
21
     * @param KeyToScriptHelper $helper
22
     */
23 21
    public function __construct(KeyToScriptHelper $helper = null)
24
    {
25 21
        $this->helper = $helper ?: new KeyToScriptHelper(Bitcoin::getEcAdapter());
26 21
    }
27
28
    /**
29
     * @param PrefixRegistry $registry
30
     * @param ScriptDataFactory $factory
31
     * @return ScriptPrefix
32
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
33
     */
34 21
    private function loadPrefix(PrefixRegistry $registry, ScriptDataFactory $factory)
35
    {
36 21
        list ($private, $public) = $registry->getPrefixes($factory->getScriptType());
37 21
        return new ScriptPrefix($factory, $private, $public);
38
    }
39
40
    /**
41
     * @param PrefixRegistry $registry
42
     * @return ScriptPrefix
43
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
44
     */
45 6
    public function xpubP2pkh(PrefixRegistry $registry)
46
    {
47 6
        return $this->loadPrefix($registry, $this->helper->getP2pkhFactory());
48
    }
49
50
    /**
51
     * @param PrefixRegistry $registry
52
     * @return ScriptPrefix
53
     * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException
54
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
55
     */
56 5
    public function ypubP2shP2wpkh(PrefixRegistry $registry)
57
    {
58 5
        return $this->loadPrefix($registry, $this->helper->getP2shFactory($this->helper->getP2wpkhFactory()));
59
    }
60
61
    /**
62
     * @param PrefixRegistry $registry
63
     * @return ScriptPrefix
64
     * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException
65
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
66
     */
67 2
    public function ypubP2shP2wshP2pkh(PrefixRegistry $registry)
68
    {
69 2
        return $this->loadPrefix($registry, $this->helper->getP2shP2wshFactory($this->helper->getP2pkhFactory()));
70
    }
71
72
    /**
73
     * @param PrefixRegistry $registry
74
     * @return ScriptPrefix
75
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
76
     */
77 6
    public function zpubP2wpkh(PrefixRegistry $registry)
78
    {
79 6
        return $this->loadPrefix($registry, $this->helper->getP2wpkhFactory());
80
    }
81
82
    /**
83
     * @param PrefixRegistry $registry
84
     * @return ScriptPrefix
85
     * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException
86
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
87
     */
88 2
    public function zpubP2wshP2pkh(PrefixRegistry $registry)
89
    {
90 2
        return $this->loadPrefix($registry, $this->helper->getP2wshFactory($this->helper->getP2pkhFactory()));
91
    }
92
}
93