本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
});
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
});
}
示例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);
}
示例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);
}
示例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";
示例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";
}