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

Slip132::p2shP2wshMultisig()   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 4
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\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