1 | <?php |
||
19 | class PrivateKeyFactory |
||
20 | { |
||
21 | /** |
||
22 | * @param bool $compressed |
||
23 | * @param EcAdapterInterface|null $ecAdapter |
||
24 | * @return PrivateKeyInterface |
||
25 | * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure |
||
26 | */ |
||
27 | 15 | public static function create(bool $compressed = false, EcAdapterInterface $ecAdapter = null): PrivateKeyInterface |
|
28 | { |
||
29 | 15 | return self::fromBuffer(self::generateSecret(), $compressed, $ecAdapter); |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * Generate a buffer containing a valid key |
||
34 | * |
||
35 | * @param EcAdapterInterface|null $ecAdapter |
||
36 | * @return BufferInterface |
||
37 | * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure |
||
38 | */ |
||
39 | 15 | public static function generateSecret(EcAdapterInterface $ecAdapter = null): BufferInterface |
|
50 | |||
51 | /** |
||
52 | * @param string $hex |
||
53 | * @param bool $compressed |
||
54 | * @param EcAdapterInterface|null $ecAdapter |
||
55 | * @return PrivateKeyInterface |
||
56 | * @throws \Exception |
||
57 | */ |
||
58 | 39 | public static function fromHex(string $hex, bool $compressed = false, EcAdapterInterface $ecAdapter = null): PrivateKeyInterface |
|
62 | |||
63 | /** |
||
64 | * @param BufferInterface $buffer |
||
65 | * @param bool $compressed |
||
66 | * @param EcAdapterInterface $ecAdapter |
||
67 | * @return PrivateKeyInterface |
||
68 | */ |
||
69 | 86 | public static function fromBuffer(BufferInterface $buffer, bool $compressed, EcAdapterInterface $ecAdapter = null): PrivateKeyInterface |
|
83 | |||
84 | /** |
||
85 | * @param int|string $int |
||
86 | * @param bool $compressed |
||
87 | * @param EcAdapterInterface|null $ecAdapter |
||
88 | * @return PrivateKeyInterface |
||
89 | */ |
||
90 | 21 | public static function fromInt($int, bool $compressed = false, EcAdapterInterface $ecAdapter = null) |
|
96 | |||
97 | /** |
||
98 | * @param string $wif |
||
99 | * @param EcAdapterInterface|null $ecAdapter |
||
100 | * @param NetworkInterface|null $network |
||
101 | * @return PrivateKeyInterface |
||
102 | * @throws InvalidPrivateKey |
||
103 | * @throws \BitWasp\Bitcoin\Exceptions\Base58ChecksumFailure |
||
104 | */ |
||
105 | 7 | public static function fromWif(string $wif, EcAdapterInterface $ecAdapter = null, NetworkInterface $network = null) |
|
116 | } |
||
117 |