nicolasflamel / secp256k1-zkp
libsecp256k1-zkp部分的PHP库
Requires
- php: >=8.0.0
This package is not auto-updated.
Last update: 2024-09-22 18:51:05 UTC
README
描述
PHP库,用于libsecp256k1-zkp的部分功能。
安装
从您项目的根目录运行以下命令来安装此库并配置项目使用它。
composer require nicolasflamel/secp256k1-zkp
使用
创建一个Secp256k1Zkp
对象后,可以使用它来执行此库实现的全部secp256k1-zkp函数。
以下代码简要展示了如何使用此库。更完整的示例可以在这里找到。
<?php
// Require dependencies
require_once __DIR__ . "/vendor/autoload.php";
// Use secp256k1-zkp
use Nicolasflamel\Secp256k1Zkp\Secp256k1Zkp;
// Initialize secp256k1-zkp
$secp256k1Zkp = new Secp256k1Zkp();
// Get if private key is valid
$privateKeyIsValid = $secp256k1Zkp->isValidPrivateKey(hex2bin("8c3882fbd7966085e760e000b1ea9eb1ad3df1eec02e720adaa5104c6bd9fd88"));
// Get public key
$publicKey = $secp256k1Zkp->getPublicKey(hex2bin("8c3882fbd7966085e760e000b1ea9eb1ad3df1eec02e720adaa5104c6bd9fd88"));
// Add private keys
$privateKeySum = hex2bin("8c3882fbd7966085e760e000b1ea9eb1ad3df1eec02e720adaa5104c6bd9fd88");
$secp256k1Zkp->addPrivateKeys($privateKeySum, hex2bin("7f64b1861b9139c0601f637957826da80bb3773adbc8c70265a0c3edb6fda33b"));
// Get blinding factor
$blindingFactor = $secp256k1Zkp->getBlindingFactor(hex2bin("8c3882fbd7966085e760e000b1ea9eb1ad3df1eec02e720adaa5104c6bd9fd88"), "123456789");
// Get commitment
$commitment = $secp256k1Zkp->getCommitment(hex2bin("8c3882fbd7966085e760e000b1ea9eb1ad3df1eec02e720adaa5104c6bd9fd88"), "123456789");
// Get Bulletproof
$bulletproof = $secp256k1Zkp->getBulletproof(hex2bin("08883a3f816419d4ce5bf44e320c24c5b09b0621c70fb780d7a35c86570bd354"), "123456789", hex2bin("74265668b4c2d901b5835de953f3ba1e1d7ce88b7e8ca89e6256145404aac330"), hex2bin("583f58e1515282cfd576319867afb4f612461993c0061a344b89e13056725eab"), hex2bin("000000021cadecb940302338354182ee67a213ba"));
// Get private nonce
$privateNonce = $secp256k1Zkp->getPrivateNonce();
// Combine public keys
$combinedPublicKey = $secp256k1Zkp->combinePublicKeys([hex2bin("03e7e3dd547cc3171ffdc403824fcc5d5d03712a29f459ca10668c2864c088e951"), hex2bin("033c44db7d8accfb8d89ada18934c4e5daf9902df8638a3e959d8d57aa6ca977cd"), hex2bin("03011d606ad1bd8470d1b6dbf6cb5eae25e42ea1b55915a0899b5a26020c59bd6f")]);
// Get partial single-signer signature
$partialSingleSignerSignature = $secp256k1Zkp->getPartialSingleSignerSignature(hex2bin("8c3882fbd7966085e760e000b1ea9eb1ad3df1eec02e720adaa5104c6bd9fd88"), hex2bin("10f3f976ecfd891b95ac8dddec7ca41685f5e5b034facba4a3ef8c3d319fea54"), hex2bin("e770cbe631b86e65417355157d4696c0a9eff485a8f0a0b005a4e86e5e31f9c9"), hex2bin("02500d2963a767c6be0121b2ca0350f54b37473be066a2d30dbbc4065d5b1fee41"), hex2bin("03fdfbccfaecc71ce664b2e03b8fb535ef8497ea743a0d2644cfb267524b6c7cee"));
// Convert public key to commitment
$commitment = $secp256k1Zkp->publicKeyToCommitment(hex2bin("02883a3f816419d4ce5bf44e320c24c5b09b0621c70fb780d7a35c86570bd35475"));
?>
函数
-
Secp256k1-zkp构造函数:
constructor(): Secp256k1Zkp
此构造函数用于创建一个
Secp256k1Zkp
对象,并返回以下值Secp256k1Zkp
:一个Secp256k1Zkp
对象。
-
Secp256k1-zkp验证私钥方法:
isValidPrivateKey(string $privateKey): bool
此方法用于检查提供的私钥是否有效,并接受以下参数
string $privateKey
:要验证的私钥。
此方法返回以下值
bool
:如果私钥有效则返回TRUE
,否则返回FALSE
。
-
Secp256k1-zkp获取公钥方法:
getPublicKey(string $privateKey): string | FALSE
此方法用于获取提供的私钥的公钥,并接受以下参数
string $privateKey
:要获取公钥的私钥。
此方法返回以下值
string
:私钥的公钥。FALSE
:获取公钥失败。
-
Secp256k1-zkp添加私钥方法:
addPrivateKeys(string &$firstPrivateKey, string $secondPrivateKey): bool
此方法用于添加两个私钥,并接受以下参数
string &$firstPrivateKey
:要将第二个私钥添加到的私钥。如果函数返回TRUE
,则此变量将包含私钥之和。string $secondPrivateKey
:要添加到第一个私钥的私钥。
此方法返回以下值
bool
:如果添加私钥成功则返回TRUE
,否则返回FALSE
。
-
Secp256k1-zkp获取遮蔽因子方法:
getBlindingFactor(string $blind, string $value): string | FALSE
此方法用于从提供的遮蔽值和价值中获取遮蔽因子,并接受以下参数
string $blind
:要使用的遮蔽。string $value
:要使用的价值。这必须是一个非负整数。
此方法返回以下值
string
:提供的遮蔽和价值对应的遮蔽因子。FALSE
:获取遮蔽因子失败。
-
Secp256k1-zkp获取承诺方法:
getCommitment(string $blindingFactor, string $value): string | FALSE
此方法用于使用提供的遮蔽因子获取提供值的承诺,并接受以下参数
string $blindingFactor
:要使用的遮蔽因子。string $value
:要承诺的价值。这必须是一个非负整数。
此方法返回以下值
string
:使用提供的遮蔽因子对提供的价值进行承诺的结果。FALSE
:获取承诺失败。
-
Secp256k1-zkp获取Bulletproof方法:
getBulletproof(string $blindingFactor, string $value, string $rewindNonce, string $privateNonce, string $message): string | FALSE
此方法用于获取与提供的盲化因子、重置随机数、私用随机数和消息相结合的值的安全证明,并接受以下参数
string $blindingFactor
:用于提交值的盲化因子。string $value
:提交的值。这必须是非负整数。string $rewindNonce
:要使用的重置随机数。string $privateNonce
:要使用的私用随机数。string $message
:要使用的信息。
此方法返回以下值
string
:使用提供重置随机数、私用随机数和消息提交的值与提供的盲化因子结合得到的安全证明。FALSE
:获取安全证明失败。
-
Secp256k1-zkp 获取私用随机数方法:
getPrivateNonce(): string | FALSE
此方法用于获取在创建部分单签名签名时可以使用的随机私用随机数,并返回以下值
string
:私用随机数。FALSE
:获取私用随机数失败。
-
Secp256k1-zkp 合并公钥方法:
combinePublicKeys(array $publicKeys): string | FALSE
此方法用于获取提供的公钥的合并公钥,并接受以下参数
array $publicKeys
:要合并的公钥。
此方法返回以下值
string
:合并后的公钥。FALSE
:合并公钥失败。
-
Secp256k1-zkp 获取部分单签名签名方法:
getPartialSingleSignerSignature(string $privateKey, string $message, string $privateNonce, string $publicKey, string $publicNonce): string | FALSE
此方法用于获取使用提供的私钥、私用随机数、公钥和公用随机数签名的提供的消息的部分单签名,并接受以下参数
string $privateKey
:要使用的私钥。string $message
:要签名的信息。string $privateNonce
:要使用的私用随机数。string $publicKey
:要使用的公钥。string $publicNonce
:要使用的公用随机数。
此方法返回以下值
string
:使用提供的私钥、私用随机数、公钥和公用随机数签名的提供的消息的部分单签名。FALSE
:获取部分单签名失败。
-
Secp256k1-zkp 公钥到承诺方法:
publicKeyToCommitment(string $publicKey): string | FALSE
此方法用于将提供的公钥转换为承诺,并接受以下参数
string $publicKey
:要转换为承诺的公钥。
此方法返回以下值
string
:承诺。FALSE
:转换公钥失败。