Exemplo n.º 1
0
 /**
  * @param int $m
  * @param PublicKeyInterface[] $keys
  * @param bool|true $sort
  * @return ScriptCreator|Script
  */
 public function multisig($m, array $keys = [], $sort = true)
 {
     $n = count($keys);
     if ($m > $n) {
         throw new \LogicException('Required number of sigs exceeds number of public keys');
     }
     if ($n > 16) {
         throw new \LogicException('Number of public keys is greater than 16');
     }
     if ($sort) {
         $keys = Buffertools::sort($keys);
     }
     $opM = \BitWasp\Bitcoin\Script\encodeOpN($m);
     $opN = \BitWasp\Bitcoin\Script\encodeOpN($n);
     $script = ScriptFactory::create();
     foreach ($keys as $key) {
         if (!$key instanceof PublicKeyInterface) {
             throw new \LogicException('Values in $keys[] must be a PublicKey');
         }
         $script->push($key->getBuffer());
     }
     $keyBuf = $script->getScript()->getBuffer();
     $script = new Script(new Buffer(chr($opM) . $keyBuf->getBinary() . chr($opN) . chr(Opcodes::OP_CHECKMULTISIG)));
     return $script;
 }
Exemplo n.º 2
0
 /**
  * @param                   $m
  * @param KeyInterface[]    $keys
  * @param bool              $sort
  * @return RedeemScript
  */
 public static function multisig($m, array $keys = array(), $sort = true)
 {
     if ($sort) {
         $keys = \BitWasp\Buffertools\Buffertools::sort($keys);
     }
     return new RedeemScript($m, $keys);
 }
Exemplo n.º 3
0
 public function testSortCallable()
 {
     $items = $this->getUnsortedList();
     $sorted = Buffertools::sort($items, function ($a) {
         return Buffer::hex($a);
     });
     $this->assertEquals($this->getSortedList(), $sorted);
 }
Exemplo n.º 4
0
 /**
  * @param int|string $m
  * @param string $path
  * @param array $keys
  * @param HierarchicalKeySequence $sequences
  * @param bool $sort
  */
 public function __construct($m, $path, array $keys, HierarchicalKeySequence $sequences, $sort = false)
 {
     if (count($keys) < 1) {
         throw new \RuntimeException('Must have at least one HierarchicalKey for Multisig HD Script');
     }
     // Sort here to guarantee calls to getKeys() returns keys in the same order as the redeemScript.
     if ($sort) {
         $keys = Buffertools::sort($keys, function (HierarchicalKey $key) {
             return $key->getPublicKey()->getBuffer();
         });
     }
     $this->m = $m;
     $this->path = $path;
     foreach ($keys as $key) {
         $this->keys[] = $key;
     }
     $this->sequences = $sequences;
     $this->sort = $sort;
 }
Exemplo n.º 5
0
 /**
  * @param HierarchicalKey[] $keys
  * @return HierarchicalKey[]
  */
 private function sortHierarchicalKeys(array $keys)
 {
     return Buffertools::sort($keys, function (HierarchicalKey $key) {
         return $key->getPublicKey()->getBuffer();
     });
 }