Completed
Pull Request — 0.0.35 (#707)
by thomas
23:28 queued 13:02
created

Slip132   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

7 Methods

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