Пример #1
0
 /**
  * @param Consensus $consensus
  * @param EcAdapterInterface $ecAdapter
  * @param ScriptCheckInterface $scriptCheck
  */
 public function __construct(Consensus $consensus, EcAdapterInterface $ecAdapter, ScriptCheckInterface $scriptCheck)
 {
     $this->consensus = $consensus;
     $this->math = $ecAdapter->getMath();
     $this->scriptCheck = $scriptCheck;
     $this->params = $consensus->getParams();
 }
Пример #2
0
 /**
  * @param Db $db
  * @param EcAdapterInterface $ecAdapter
  * @param Consensus $consensus
  * @param BlockCheckInterface $blockCheck
  */
 public function __construct(Db $db, EcAdapterInterface $ecAdapter, Consensus $consensus, BlockCheckInterface $blockCheck)
 {
     $this->blockCheck = $blockCheck;
     $this->consensus = $consensus;
     $this->db = $db;
     $this->math = $ecAdapter->getMath();
 }
Пример #3
0
 /**
  * @param $mnemonic
  * @return Buffer
  */
 public function mnemonicToEntropy($mnemonic)
 {
     $math = $this->ecAdapter->getMath();
     $words = explode(' ', $mnemonic);
     if ($math->cmp($math->mod(count($words), 3), 0) !== 0) {
         throw new \InvalidArgumentException('Invalid mnemonic');
     }
     $bits = array();
     foreach ($words as $word) {
         $idx = $this->wordList->getIndex($word);
         $bits[] = str_pad($math->baseConvert($idx, 10, 2), 11, '0', STR_PAD_LEFT);
     }
     $bits = implode('', $bits);
     $CS = strlen($bits) / 33;
     $ENT = strlen($bits) - $CS;
     $csBits = substr($bits, -1 * $CS);
     $entBits = substr($bits, 0, -1 * $CS);
     $binary = '';
     $bitsInChar = 8;
     for ($i = 0; $i < $ENT; $i += $bitsInChar) {
         // Extract 8 bits at a time, convert to hex, pad, and convert to binary.
         $eBits = substr($entBits, $i, $bitsInChar);
         $binary .= hex2bin(str_pad($math->baseConvert($eBits, 2, 16), 2, '0', STR_PAD_LEFT));
     }
     $entropy = new Buffer($binary, null, $math);
     if ($csBits !== $this->calculateChecksum($entropy, $CS)) {
         throw new \InvalidArgumentException('Checksum does not match');
     }
     return $entropy;
 }
Пример #4
0
 /**
  * @param string $mnemonic
  * @return Buffer
  */
 public function mnemonicToEntropy($mnemonic)
 {
     $math = $this->ecAdapter->getMath();
     $wordList = $this->wordList;
     $words = explode(' ', $mnemonic);
     $n = count($wordList);
     $out = '';
     $thirdWordCount = count($words) / 3;
     for ($i = 0; $i < $thirdWordCount; $i++) {
         list($word1, $word2, $word3) = array_slice($words, $math->mul(3, $i), 3);
         $index1 = $wordList->getIndex($word1);
         $index2 = $wordList->getIndex($word2);
         $index3 = $wordList->getIndex($word3);
         $x = $math->add($index1, $math->add($math->mul($n, $math->mod($index2 - $index1, $n)), $math->mul($n, $math->mul($n, $math->mod($index3 - $index2, $n)))));
         $out .= str_pad($math->decHex($x), 8, '0', STR_PAD_LEFT);
     }
     return Buffer::hex($out);
 }
Пример #5
0
 /**
  * Blocks constructor.
  * @param DbInterface $db
  * @param ConfigProviderInterface $config
  * @param EcAdapterInterface $ecAdapter
  * @param ChainsInterface $chains
  * @param Consensus $consensus
  */
 public function __construct(DbInterface $db, ConfigProviderInterface $config, EcAdapterInterface $ecAdapter, ChainsInterface $chains, Consensus $consensus)
 {
     $this->db = $db;
     $this->config = $config;
     $this->math = $ecAdapter->getMath();
     $this->chains = $chains;
     $this->consensus = $consensus;
     $this->blockCheck = new BlockCheck($consensus, $ecAdapter);
 }
Пример #6
0
 /**
  * Headers constructor.
  * @param DbInterface $db
  * @param EcAdapterInterface $ecAdapter
  * @param ChainsInterface $chains
  * @param Consensus $consensus
  * @param ProofOfWork $proofOfWork
  */
 public function __construct(DbInterface $db, EcAdapterInterface $ecAdapter, ChainsInterface $chains, Consensus $consensus, ProofOfWork $proofOfWork)
 {
     $this->db = $db;
     $this->math = $ecAdapter->getMath();
     $this->chains = $chains;
     $this->consensus = $consensus;
     $this->proofOfWork = $proofOfWork;
     $this->headerCheck = new HeaderCheck($consensus, $ecAdapter, $proofOfWork);
 }
Пример #7
0
 /**
  * @param EcAdapterInterface $ecAdapter
  */
 public function __construct(EcAdapterInterface $ecAdapter)
 {
     $this->ecAdapter = $ecAdapter;
     $this->math = $ecAdapter->getMath();
     $this->vchFalse = new Buffer("", 0, $this->math);
     $this->vchTrue = new Buffer("", 1, $this->math);
     $this->int0 = Number::buffer($this->vchFalse, false, 4, $this->math)->getBuffer();
     $this->int1 = Number::buffer($this->vchTrue, false, 1, $this->math)->getBuffer();
 }
Пример #8
0
 /**
  * @param \BitWasp\Bitcoin\Script\Interpreter\Number $sequence
  * @return bool
  */
 public function checkSequence(\BitWasp\Bitcoin\Script\Interpreter\Number $sequence)
 {
     $math = $this->adapter->getMath();
     $txSequence = $this->transaction->getInput($this->nInput)->getSequence();
     if ($this->transaction->getVersion() < 2) {
         return false;
     }
     if ($math->cmp($math->bitwiseAnd($txSequence, TransactionInputInterface::SEQUENCE_LOCKTIME_DISABLE_FLAG), 0) !== 0) {
         return 0;
     }
     $mask = $math->bitwiseOr(TransactionInputInterface::SEQUENCE_LOCKTIME_TYPE_FLAG, TransactionInputInterface::SEQUENCE_LOCKTIME_MASK);
     return $this->verifyLockTime($math->bitwiseAnd($txSequence, $mask), TransactionInputInterface::SEQUENCE_LOCKTIME_TYPE_FLAG, Number::int($math->bitwiseAnd($sequence->getInt(), $mask)));
 }
Пример #9
0
 /**
  * @param EcAdapterInterface $ecAdapter
  * @param TransactionInterface $transaction
  * @param \BitWasp\Bitcoin\Flags $flags
  */
 public function __construct(EcAdapterInterface $ecAdapter, TransactionInterface $transaction, Flags $flags)
 {
     $this->ecAdapter = $ecAdapter;
     $this->math = $ecAdapter->getMath();
     $this->transaction = $transaction;
     $this->flags = $flags;
     $this->script = new Script();
     $this->minimalPush = $this->flags->checkFlags(self::VERIFY_MINIMALDATA) === true;
     $this->vchFalse = new Buffer("", 0, $this->math);
     $this->vchTrue = new Buffer("", 1, $this->math);
     $this->mainStack = new Stack();
     $this->altStack = new Stack();
     $this->vfStack = new Stack();
     $this->int0 = Number::buffer($this->vchFalse, false, 4, $this->math)->getBuffer();
     $this->int1 = Number::buffer($this->vchTrue, false, 1, $this->math)->getBuffer();
 }
Пример #10
0
 /**
  * @param Consensus $consensus
  * @param EcAdapterInterface $ecAdapter
  * @param ProofOfWork $proofOfWork
  */
 public function __construct(Consensus $consensus, EcAdapterInterface $ecAdapter, ProofOfWork $proofOfWork)
 {
     $this->consensus = $consensus;
     $this->math = $ecAdapter->getMath();
     $this->pow = $proofOfWork;
 }
Пример #11
0
 /**
  * Decodes a BIP32 path into actual 32bit sequence numbers and derives the child key
  *
  * @param string $path
  * @return HierarchicalKey
  * @throws \Exception
  */
 public function derivePath($path)
 {
     $sequences = new HierarchicalKeySequence($this->ecAdapter->getMath());
     return $this->deriveFromList($sequences->decodePath($path));
 }
Пример #12
0
 /**
  * @param string $message
  * @return BufferInterface
  * @throws \Exception
  */
 private function calculateBody($message)
 {
     return new Buffer("Bitcoin Signed Message:\n" . Buffertools::numToVarInt(strlen($message))->getBinary() . $message, null, $this->ecAdapter->getMath());
 }
Пример #13
0
 /**
  * @param int|string $sequence
  * @param bool $change
  * @return int|string
  */
 public function getSequenceOffset($sequence, $change = false)
 {
     return Hash::sha256d(new Buffer(sprintf("%s:%s:%s", $sequence, $change ? '1' : '0', $this->getMPK()->getBinary()), null, $this->ecAdapter->getMath()))->getInt();
 }
Пример #14
0
 /**
  * @param int $bytes
  * @return Buffer
  */
 public function bytes($bytes)
 {
     $integer = $this->hmac->generate($this->ecAdapter->getGenerator()->getOrder());
     return Buffer::int($integer, $bytes, $this->ecAdapter->getMath());
 }
Пример #15
0
 /**
  * @param Consensus $consensus
  * @param EcAdapterInterface $ecAdapter
  */
 public function __construct(Consensus $consensus, EcAdapterInterface $ecAdapter)
 {
     $this->consensus = $consensus;
     $this->math = $ecAdapter->getMath();
 }
Пример #16
0
 public function compareChainStateWork(ChainState $a, ChainState $b)
 {
     return $this->adapter->getMath()->cmp($a->getChain()->getIndex()->getWork(), $b->getChain()->getIndex()->getWork());
 }