Completed
Push — master ( 460d12...eabe8c )
by thomas
24:52
created

Slip132   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

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