当前位置: 首页>>代码示例>>PHP>>正文


PHP Bitcoin::getEcAdapter方法代码示例

本文整理汇总了PHP中BitWasp\Bitcoin\Bitcoin::getEcAdapter方法的典型用法代码示例。如果您正苦于以下问题:PHP Bitcoin::getEcAdapter方法的具体用法?PHP Bitcoin::getEcAdapter怎么用?PHP Bitcoin::getEcAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitWasp\Bitcoin\Bitcoin的用法示例。


在下文中一共展示了Bitcoin::getEcAdapter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getNativeConsensus

 /**
  * @param int|null $flags
  * @param EcAdapterInterface|null $ecAdapter
  * @return NativeConsensus
  */
 public static function getNativeConsensus($flags = null, EcAdapterInterface $ecAdapter = null)
 {
     if ($flags === null) {
         $flags = self::defaultFlags();
     }
     return new NativeConsensus($ecAdapter ?: Bitcoin::getEcAdapter(), $flags);
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:12,代码来源:ScriptFactory.php

示例2: fromHex

 /**
  * @param \BitWasp\Buffertools\Buffer|string $string
  * @param EcAdapterInterface $ecAdapter
  * @return SignatureInterface
  */
 public static function fromHex($string, EcAdapterInterface $ecAdapter = null)
 {
     $ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
     $serializer = EcSerializer::getSerializer($ecAdapter, 'BitWasp\\Bitcoin\\Crypto\\EcAdapter\\Serializer\\Signature\\DerSignatureSerializerInterface');
     /** @var DerSignatureSerializerInterface $serializer */
     return $serializer->parse($string);
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:12,代码来源:SignatureFactory.php

示例3: fromHex

 /**
  * @param string $hex
  * @param bool $compressed
  * @param EcAdapterInterface|null $ecAdapter
  * @return PrivateKey
  */
 public static function fromHex($hex, $compressed = false, EcAdapterInterface $ecAdapter = null)
 {
     $hex = Buffer::hex($hex);
     $ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
     $hexSerializer = new HexPrivateKeySerializer($ecAdapter);
     return $hexSerializer->parse($hex)->setCompressed($compressed);
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:13,代码来源:PrivateKeyFactory.php

示例4: __construct

 public function __construct()
 {
     parent::__construct(function () {
         $consensus = new ConsensusFactory(Bitcoin::getEcAdapter());
         $loop = LoopFactory::create();
         $context = new ZmqContext($loop);
         $control = $context->getSocket(\ZMQ::SOCKET_SUB);
         $control->connect('tcp://127.0.0.1:5594');
         $control->subscribe('control');
         $control->on('messages', function ($msg) use($loop) {
             if ($msg[1] == 'shutdown') {
                 $loop->stop();
             }
         });
         $results = $context->getSocket(\ZMQ::SOCKET_PUSH);
         $results->connect("tcp://127.0.0.1:5593");
         $workers = $context->getSocket(\ZMQ::SOCKET_PULL);
         $workers->connect('tcp://127.0.0.1:5592');
         $workers->on('message', function ($message) use($consensus, $results) {
             $details = json_decode($message, true);
             $txid = $details['txid'];
             $flags = $details['flags'];
             $vin = $details['vin'];
             $scriptPubKey = new Script(Buffer::hex($details['scriptPubKey']));
             $tx = TransactionFactory::fromHex($details['tx']);
             $results->send(json_encode(['txid' => $txid, 'vin' => $vin, 'result' => $consensus->getConsensus(new Flags($flags))->verify($tx, $scriptPubKey, $vin)]));
         });
         $loop->run();
         exit(0);
     });
 }
开发者ID:sbwdlihao,项目名称:node-php,代码行数:31,代码来源:ScriptWorkerThread.php

示例5: fromParser

 /**
  * @param Parser $parser
  * @return Alert
  */
 public function fromParser(Parser $parser)
 {
     $detail = $this->detail->fromParser($parser);
     list($sigBuffer) = $this->getSigBuf()->parse($parser);
     $adapter = Bitcoin::getEcAdapter();
     $serializer = EcSerializer::getSerializer('BitWasp\\Bitcoin\\Crypto\\EcAdapter\\Serializer\\Signature\\DerSignatureSerializerInterface', true, $adapter);
     $sig = $serializer->parse($sigBuffer);
     return new Alert($detail, $sig);
 }
开发者ID:Bit-Wasp,项目名称:bitcoin-p2p-php,代码行数:13,代码来源:AlertSerializer.php

示例6: fromHex

 /**
  * @param \BitWasp\Buffertools\BufferInterface|string $hex
  * @param bool $compressed
  * @param EcAdapterInterface|null $ecAdapter
  * @return PrivateKey
  */
 public static function fromHex($hex, $compressed = false, EcAdapterInterface $ecAdapter = null)
 {
     $ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
     /** @var PrivateKeySerializerInterface $serializer */
     $serializer = EcSerializer::getSerializer($ecAdapter, 'BitWasp\\Bitcoin\\Crypto\\EcAdapter\\Serializer\\Key\\PrivateKeySerializerInterface');
     $parsed = $serializer->parse($hex);
     if ($compressed) {
         $parsed = $ecAdapter->getPrivateKey($parsed->getSecretMultiplier(), $compressed);
     }
     return $parsed;
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:17,代码来源:PrivateKeyFactory.php

示例7: discover_wallet_addrs_multisig

 protected function discover_wallet_addrs_multisig($xpub_list)
 {
     foreach ($xpub_list as $pk) {
         $k[] = HierarchicalKeyFactory::fromExtended($pk, Bitcoin::getNetwork());
     }
     $params = $this->get_params();
     $num_signers = $params['numsig'];
     $ec = \BitWasp\Bitcoin\Bitcoin::getEcAdapter();
     $sequences = new \BitWasp\Bitcoin\Key\Deterministic\HierarchicalKeySequence($ec->getMath());
     $hd = new \BitWasp\Bitcoin\Key\Deterministic\MultisigHD($num_signers, 'm/44', $k, $sequences, true);
     return $this->discover_addrs($hd);
 }
开发者ID:dan-da,项目名称:hd-wallet-addrs,代码行数:12,代码来源:walletaddrs.class.php

示例8: sign

 /**
  * Sign hex data deterministically using deterministic k.
  *
  * @param string $hexDataToSign
  * @param PrivateKeyInterface|string $privateKey
  * @return string
  */
 public static function sign($hexDataToSign, $privateKey)
 {
     if (is_string($privateKey)) {
         $privateKey = PrivateKeyManipulator::importPrivateKey($privateKey);
     }
     // Convert hex data to buffer
     $data = Buffer::hex($hexDataToSign);
     /** @var EcAdapterInterface $ecAdapter */
     $ecAdapter = Bitcoin::getEcAdapter();
     // Deterministic digital signature generation
     $k = new Rfc6979($ecAdapter, $privateKey, $data, 'sha256');
     $sig = $ecAdapter->sign($data, $privateKey, $k);
     // DEBUG
     //echo "hexDataToSign: <br/>";
     //var_dump($hexDataToSign);
     //echo "sig: <br/>";
     //var_dump($sig->getHex());
     return $sig->getHex();
 }
开发者ID:toneloc,项目名称:php-client,代码行数:26,代码来源:Signer.php

示例9: __construct

 /**
  * BetterNode constructor.
  * @param ConfigProviderInterface $config
  * @param ParamsInterface $params
  * @param DbInterface $db
  */
 public function __construct(ConfigProviderInterface $config, ParamsInterface $params, DbInterface $db)
 {
     $math = Bitcoin::getMath();
     $adapter = Bitcoin::getEcAdapter($math);
     $this->chains = new ChainContainer($math, $params);
     $consensus = new Consensus($math, $params);
     $pow = new ProofOfWork($math, $params);
     $this->headers = new Index\Headers($db, $adapter, $this->chains, $consensus, $pow);
     $this->blocks = new Index\Blocks($db, $config, $adapter, $this->chains, $consensus);
     $this->transactions = new Index\Transactions($db);
     $genesis = $params->getGenesisBlock();
     $this->headers->init($genesis->getHeader());
     $this->blocks->init($genesis);
     $this->db = $db;
     $segments = $this->db->fetchChainSegments();
     foreach ($segments as $segment) {
         $this->chains->addSegment($segment);
     }
     $this->chains->initialize($this->db);
 }
开发者ID:Bit-Wasp,项目名称:node-php,代码行数:26,代码来源:BitcoinNode.php

示例10: fromParser

 /**
  * @param Parser $parser
  * @return Alert
  */
 public function fromParser(Parser &$parser)
 {
     $detail = $this->detail->fromParser($parser);
     list($sigR, $sigS) = $this->getSigTemplate()->parse($parser);
     $adapter = Bitcoin::getEcAdapter();
     if (!$adapter instanceof \BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter) {
         // We need to serialize this as DER, and deserialize it using the correct serializer...
         $temporary = new \BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter($adapter->getMath(), $adapter->getGenerator());
         $sig = new \BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Signature\Signature($temporary, $sigR, $sigS);
         $serializer = new \BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Signature\DerSignatureSerializer($temporary);
         $serialized = $serializer->serialize($sig);
         // Parse using native EcAdapter
         /** @var \BitWasp\Bitcoin\Crypto\EcAdapter\Serializer\Signature\DerSignatureSerializerInterface $serializer */
         $serializer = EcSerializer::getSerializer($adapter, 'BitWasp\\Bitcoin\\Crypto\\EcAdapter\\Serializer\\Signature\\DerSignatureSerializerInterface');
         $sig = $serializer->parse($serialized);
     } else {
         $sig = new \BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Signature\Signature($adapter, $sigR, $sigS);
     }
     return new Alert($detail, $sig);
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:24,代码来源:AlertSerializer.php

示例11: testCreateInstance

 public function testCreateInstance()
 {
     $ecAdapter = Bitcoin::getEcAdapter();
     $params = new Params($ecAdapter->getMath());
     $consensus = new Consensus($ecAdapter->getMath(), $params);
     $proofOfWork = new ProofOfWork($ecAdapter->getMath(), $params);
     $check = new HeaderCheck($consensus, $ecAdapter, $proofOfWork);
     $header = BlockHeaderFactory::fromHex($this->getGenesisHex());
     $hash = $header->getHash();
     $this->assertNoException(function () use($check, $hash, $header) {
         $check->check($hash, $header, false);
     });
     $this->assertNoException(function () use($check, $hash, $header) {
         $check->check($hash, $header, true);
     });
     $badHeader = new BlockHeader($header->getVersion(), $header->getPrevBlock(), $header->getMerkleRoot(), $header->getTimestamp(), $header->getBits(), 1);
     $this->assertException(function () use($check, $badHeader) {
         $hash = $badHeader->getHash();
         $check->check($hash, $badHeader, true);
     });
 }
开发者ID:Bit-Wasp,项目名称:node-php,代码行数:21,代码来源:HeaderCheckTest.php

示例12: fromPoint

 /**
  * @param PointInterface $point
  * @param bool $compressed
  * @param EcAdapterInterface $ecAdapter
  * @return PublicKey
  */
 public static function fromPoint(PointInterface $point, $compressed = false, EcAdapterInterface $ecAdapter = null)
 {
     return new PublicKey($ecAdapter ?: Bitcoin::getEcAdapter(), $point, $compressed);
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:10,代码来源:PublicKeyFactory.php

示例13: sign

 /**
  * @param TransactionInterface $transaction
  * @param EcAdapterInterface|null $ecAdapter
  * @return TxSigner
  */
 public static function sign(TransactionInterface $transaction, EcAdapterInterface $ecAdapter = null)
 {
     return new TxSigner($ecAdapter ?: Bitcoin::getEcAdapter(), $transaction);
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:9,代码来源:TransactionFactory.php

示例14: Transaction

<?php

require_once "../vendor/autoload.php";
use BitWasp\Bitcoin\Script\ScriptFactory;
use BitWasp\Bitcoin\Transaction\Transaction;
use BitWasp\Bitcoin\Script\Script;
$ec = \BitWasp\Bitcoin\Bitcoin::getEcAdapter();
$scriptSig = ScriptFactory::create()->int(1)->int(1)->getScript();
$scriptPubKey = ScriptFactory::create()->op('OP_ADD')->int(2)->op('OP_EQUAL')->getScript();
echo "Formed script: " . $scriptSig->getHex() . " " . $scriptPubKey->getHex() . "\n";
$flags = new \BitWasp\Bitcoin\Flags(0);
$i = new \BitWasp\Bitcoin\Script\Interpreter\Interpreter($ec, new Transaction(), $flags);
$result = $i->verify($scriptSig, $scriptPubKey, 0);
echo "Script result: " . ($result ? 'true' : 'false') . "\n";
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:14,代码来源:script.simple.php

示例15: SignedMessageSerializer

<?php

require "../vendor/autoload.php";
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\MessageSigner\MessageSigner;
use BitWasp\Bitcoin\Serializer\MessageSigner\SignedMessageSerializer;
use BitWasp\Bitcoin\Serializer\Signature\CompactSignatureSerializer;
Bitcoin::setNetwork(\BitWasp\Bitcoin\Network\NetworkFactory::bitcoinTestnet());
$address = 'n2Z2DFCxG6vktyX1MFkKAQPQFsrmniGKj5';
$sig = '-----BEGIN BITCOIN SIGNED MESSAGE-----
hi
-----BEGIN SIGNATURE-----
IBpGR29vEbbl4kmpK0fcDsT75GPeH2dg5O199D3iIkS3VcDoQahJMGJEDozXot8JGULWjN9Llq79aF+FogOoz/M=
-----END BITCOIN SIGNED MESSAGE-----';
$ec = Bitcoin::getEcAdapter();
$addr = \BitWasp\Bitcoin\Address\AddressFactory::fromString($address);
$serializer = new SignedMessageSerializer(new CompactSignatureSerializer(Bitcoin::getMath()));
$signedMessage = $serializer->parse($sig);
$signer = new MessageSigner($ec);
if ($signer->verify($signedMessage, $addr)) {
    echo "Signature verified!\n";
} else {
    echo "Failed to verify signature!\n";
}
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:24,代码来源:signedmessage.verify.php


注:本文中的BitWasp\Bitcoin\Bitcoin::getEcAdapter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。