1 | <?php |
||
14 | class Bip39Mnemonic implements MnemonicInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var EcAdapterInterface |
||
18 | */ |
||
19 | private $ecAdapter; |
||
20 | |||
21 | /** |
||
22 | * @var Bip39WordListInterface |
||
23 | */ |
||
24 | private $wordList; |
||
25 | |||
26 | const MIN_ENTROPY_BYTE_LEN = 16; |
||
27 | const MAX_ENTROPY_BYTE_LEN = 32; |
||
28 | const DEFAULT_ENTROPY_BYTE_LEN = self::MAX_ENTROPY_BYTE_LEN; |
||
29 | |||
30 | private $validEntropySizes = [ |
||
31 | self::MIN_ENTROPY_BYTE_LEN * 8, 160, 192, 224, self::MAX_ENTROPY_BYTE_LEN * 8, |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * @param EcAdapterInterface $ecAdapter |
||
36 | * @param Bip39WordListInterface $wordList |
||
37 | */ |
||
38 | 6 | public function __construct(EcAdapterInterface $ecAdapter, Bip39WordListInterface $wordList) |
|
43 | |||
44 | /** |
||
45 | * Creates a new Bip39 mnemonic string. |
||
46 | * |
||
47 | * @param int $entropySize |
||
48 | * @return string |
||
49 | * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure |
||
50 | */ |
||
51 | public function create(int $entropySize = null): string |
||
66 | |||
67 | /** |
||
68 | * @param BufferInterface $entropy |
||
69 | * @param integer $CSlen |
||
70 | * @return string |
||
71 | */ |
||
72 | 49 | private function calculateChecksum(BufferInterface $entropy, int $CSlen): string |
|
83 | |||
84 | /** |
||
85 | * @param BufferInterface $entropy |
||
86 | * @return string[] - array of words from the word list |
||
87 | */ |
||
88 | 26 | public function entropyToWords(BufferInterface $entropy): array |
|
106 | |||
107 | /** |
||
108 | * @param BufferInterface $entropy |
||
109 | * @return string |
||
110 | */ |
||
111 | 26 | public function entropyToMnemonic(BufferInterface $entropy): string |
|
115 | |||
116 | /** |
||
117 | * @param string $mnemonic |
||
118 | * @return BufferInterface |
||
119 | */ |
||
120 | 27 | public function mnemonicToEntropy(string $mnemonic): BufferInterface |
|
162 | } |
||
163 |