/**
  * @param BufferInterface $entropy
  * @return array
  * @throws \Exception
  */
 public function entropyToWords(BufferInterface $entropy)
 {
     $math = $this->ecAdapter->getMath();
     $n = count($this->wordList);
     $wordArray = [];
     $chunks = $entropy->getSize() / 4;
     for ($i = 0; $i < $chunks; $i++) {
         $x = $entropy->slice(4 * $i, 4)->getInt();
         $index1 = $math->mod($x, $n);
         $index2 = $math->mod($math->add($math->div($x, $n), $index1), $n);
         $index3 = $math->mod($math->add($math->div($math->div($x, $n), $n), $index2), $n);
         $wordArray[] = $this->wordList->getWord($index1);
         $wordArray[] = $this->wordList->getWord($index2);
         $wordArray[] = $this->wordList->getWord($index3);
     }
     return $wordArray;
 }
Beispiel #2
0
 /**
  * @param BufferInterface $publicKey
  * @return PublicKeyInterface
  * @throws \Exception
  */
 public function publicKeyFromBuffer(BufferInterface $publicKey)
 {
     $compressed = $publicKey->getSize() == PublicKey::LENGTH_COMPRESSED;
     $xCoord = $publicKey->slice(1, 32)->getInt();
     return new PublicKey($this, $this->getGenerator()->getCurve()->getPoint($xCoord, $compressed ? $this->recoverYfromX($xCoord, $publicKey->slice(0, 1)->getHex()) : $publicKey->slice(33, 32)->getInt()), $compressed);
 }