Example #1
0
 /**
  * Set that this key should be compressed
  *
  * @param boolean $setting
  * @return $this
  * @throws \Exception
  */
 public function setCompressed($setting)
 {
     $this->compressed = $setting;
     $this->getPublicKey();
     $this->publicKey->setCompressed($setting);
     return $this;
 }
 /**
  * @return bool
  */
 public function isMultisig()
 {
     $opCodes = $this->script->getOpcodes();
     $count = count($this->evalScript);
     if ($count <= 3) {
         return false;
     }
     $mOp = $this->evalScript[0];
     $nOp = $this->evalScript[$count - 2];
     $lastOp = $this->evalScript[$count - 1];
     $keys = array_slice($this->evalScript, 1, -2);
     $keysValid = function () use($keys) {
         $valid = true;
         foreach ($keys as $key) {
             $valid &= $key instanceof Buffer && PublicKey::isCompressedOrUncompressed($key);
         }
         return $valid;
     };
     return $count >= 2 && is_string($mOp) && is_string($nOp) && is_string($lastOp) && $opCodes->cmp($opCodes->getOpByName($mOp), 'OP_0') >= 0 && $opCodes->cmp($opCodes->getOpByName($nOp), 'OP_16') <= 0 && $this->evalScript[$count - 1] == 'OP_CHECKMULTISIG' && $keysValid();
 }
 /**
  * @return bool
  */
 public function isMultisig()
 {
     if (count($this->evalScript) < 3) {
         return false;
     }
     $final = end($this->evalScript);
     if (!$final || !$final instanceof Buffer) {
         return false;
     }
     $script = new Script($final);
     $parsed = $script->getScriptParser()->parse();
     $count = count($parsed);
     $opCodes = $script->getOpCodes();
     $mOp = $parsed[0];
     $nOp = $parsed[$count - 2];
     $keys = array_slice($parsed, 1, -2);
     $keysValid = true;
     foreach ($keys as $key) {
         $keysValid &= $key instanceof Buffer && PublicKey::isCompressedOrUncompressed($key);
     }
     return $opCodes->cmp($opCodes->getOpByName($mOp), 'OP_0') >= 0 && $opCodes->cmp($opCodes->getOpByName($nOp), 'OP_16') <= 0 && $keysValid;
 }
Example #4
0
 /**
  * @param Buffer $publicKey
  * @return bool
  */
 public function validatePublicKey(Buffer $publicKey)
 {
     if (PublicKey::isCompressedOrUncompressed($publicKey)) {
         try {
             $this->publicKeyFromBuffer($publicKey);
             return true;
         } catch (\Exception $e) {
             // Let the function finish and return false
         }
     }
     return false;
 }
Example #5
0
 /**
  * @param Buffer $publicKey
  * @return $this
  * @throws \Exception
  */
 public function checkPublicKeyEncoding(Buffer $publicKey)
 {
     if ($this->flags->checkFlags(InterpreterInterface::VERIFY_STRICTENC) && !PublicKey::isCompressedOrUncompressed($publicKey)) {
         throw new ScriptRuntimeException(InterpreterInterface::VERIFY_STRICTENC, 'Public key with incorrect encoding');
     }
     return $this;
 }