Completed
Pull Request — master (#759)
by thomas
25:10
created

PSBTBip32Derivation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
ccs 4
cts 4
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\Transaction\PSBT;
6
7
use BitWasp\Bitcoin\Bitcoin;
8
use BitWasp\Bitcoin\Crypto\EcAdapter\Adapter\EcAdapterInterface;
9
use BitWasp\Bitcoin\Crypto\EcAdapter\EcSerializer;
10
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface;
11
use BitWasp\Bitcoin\Crypto\EcAdapter\Serializer\Key\PublicKeySerializerInterface;
12
use BitWasp\Buffertools\BufferInterface;
13
14
class PSBTBip32Derivation
15
{
16
    /**
17
     * @var int
18
     */
19
    private $masterKeyFpr;
20
21
    /**
22
     * @var int[]
23
     */
24
    private $path;
25
26
    /**
27
     * @var BufferInterface
28
     */
29
    private $rawKey;
30
31
    /**
32
     * PSBTBip32Derivation constructor.
33
     * @param BufferInterface $rawKey
34
     * @param int $fpr
35
     * @param int ...$path
36
     */
37 5
    public function __construct(BufferInterface $rawKey, int $fpr, int ...$path)
38
    {
39 5
        $this->rawKey = $rawKey;
40 5
        $this->masterKeyFpr = $fpr;
41 5
        $this->path = $path;
42 5
    }
43
44
    /**
45
     * @return int[]
46
     */
47 3
    public function getPath(): array
48
    {
49 3
        return $this->path;
50
    }
51
52 3
    public function getMasterKeyFpr(): int
53
    {
54 3
        return $this->masterKeyFpr;
55
    }
56
57 1
    public function getRawPublicKey(): BufferInterface
58
    {
59 1
        return $this->rawKey;
60
    }
61
62 1
    public function getPublicKey(EcAdapterInterface $ecAdapter = null): PublicKeyInterface
63
    {
64 1
        $ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
65 1
        $pubKeySerializer = EcSerializer::getSerializer(PublicKeySerializerInterface::class, true, $ecAdapter);
66 1
        return $pubKeySerializer->parse($this->rawKey);
67
    }
68
}
69