Completed
Push — master ( f2b04e...8782bc )
by thomas
27:42
created

Slip132::p2shP2wpkh()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
0 ignored issues
show
Unused Code introduced by
The parameter $registry is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    {
73 2
        throw new NotImplementedException("Ypub/prv not supported yet");
74
    }
75
76
    /**
77
     * zpub on bitcoin
78
     * @param PrefixRegistry $registry
79
     * @return ScriptPrefix
80
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
81
     */
82 6
    public function p2wpkh(PrefixRegistry $registry): ScriptPrefix
83
    {
84 6
        return $this->loadPrefix($registry, $this->helper->getP2wpkhFactory());
85
    }
86
87
    /**
88
     * Zpub on bitcoin
89
     * @param PrefixRegistry $registry
90
     * @return ScriptPrefix
91
     * @throws NotImplementedException
92
     */
93 2
    public function p2wshP2pkh(PrefixRegistry $registry): ScriptPrefix
0 ignored issues
show
Unused Code introduced by
The parameter $registry is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
    {
95 2
        throw new NotImplementedException("Zpub/prv not supported yet");
96
    }
97
}
98