本文整理汇总了PHP中BitWasp\Buffertools\Buffer::slice方法的典型用法代码示例。如果您正苦于以下问题:PHP Buffer::slice方法的具体用法?PHP Buffer::slice怎么用?PHP Buffer::slice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitWasp\Buffertools\Buffer
的用法示例。
在下文中一共展示了Buffer::slice方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signCompact
/**
* @param PrivateKeyInterface $privateKey
* @param Buffer $messageHash
* @param RbgInterface $rbg
* @return CompactSignature
* @throws \Exception
*/
public function signCompact(Buffer $messageHash, PrivateKeyInterface $privateKey, RbgInterface $rbg = null)
{
$sigStr = '';
$recid = 0;
$ret = \secp256k1_ecdsa_sign_compact($messageHash->getBinary(), $privateKey->getBuffer()->getBinary(), $sigStr, $recid);
if ($ret === 1) {
$sigStr = new Buffer($sigStr);
return new CompactSignature($sigStr->slice(0, 32)->getInt(), $sigStr->slice(32, 32)->getInt(), $recid, $privateKey->isCompressed());
}
throw new \Exception('Unable to create compact signature');
}
示例2: parseIpBuffer
/**
* @param Buffer $ip
* @return string
* @throws \Exception
*/
private function parseIpBuffer(Buffer $ip)
{
$end = $ip->slice(12, 4);
return implode(".", array_map(function ($int) {
return unpack("C", $int)[1];
}, str_split($end->getBinary(), 1)));
}
示例3: entropyToWords
/**
* @param Buffer $entropy
* @return array
* @throws \Exception
*/
public function entropyToWords(Buffer $entropy)
{
$math = $this->ecAdapter->getMath();
$n = count($this->wordList);
$wordArray = [];
$chunks = $entropy->getSize() / 4;
for ($i = 0; $i < $chunks; $i++) {
$x = $entropy->slice(4 * $i, 4)->getInt();
$index1 = $math->mod($x, $n);
$index2 = $math->mod($math->add($math->div($x, $n), $index1), $n);
$index3 = $math->mod($math->add($math->div($math->div($x, $n), $n), $index2), $n);
$wordArray[] = $this->wordList->getWord($index1);
$wordArray[] = $this->wordList->getWord($index2);
$wordArray[] = $this->wordList->getWord($index3);
}
return $wordArray;
}
示例4: publicKeyFromBuffer
/**
* @param Buffer $publicKey
* @return PublicKeyInterface
* @throws \Exception
*/
public function publicKeyFromBuffer(Buffer $publicKey)
{
$compressed = $publicKey->getSize() == PublicKey::LENGTH_COMPRESSED;
$xCoord = $publicKey->slice(1, 32)->getInt();
return new PublicKey($this, $this->getGenerator()->getCurve()->getPoint($xCoord, $compressed ? $this->recoverYfromX($xCoord, $publicKey->slice(0, 1)->getHex()) : $publicKey->slice(33, 32)->getInt()), $compressed);
}