验证 WAVES KEEPER Auth 签名

Verifying WAVES KEEPER Auth signature

我正在尝试在 Auth 调用中使用从 WAVES KEEPER 返回的以下数据:

address: "3Mzp4yJ3CGWTX5Wy1f67aLaTvxdCW2ZdyPj"
host: "localhost"
name: "waveslease"
prefix: "WavesWalletAuthentication"
publicKey: "43D71TX4bLGundDUYhp72vRQLd7rtA639nWK1WexfjFq"
signature: "3pzyjyUGrwgWfqsuZXdtiVsRjgGufsopas7KNqfazHnystPviDqv93ru5g1trLjXXwhKVsdBhy1jrAmk2heiXJKw"
version: 1

并使用 WavesKit PHP (https://github.com/deemru/WavesKit)

验证从 WAVES KEEPER 服务器端返回的签名

这是我的测试代码:

[...]
public function str_with_length( $data )
{       
    $string_length_bytes = bin2hex(pack('L', strlen($data)));
    $string_bytes = utf8_encode($data);
    return $string_length_bytes.$string_bytes;        
}

public function get_statistics( $address, $signature, $publickey )
{

    $wk = new deemru\WavesKit( 'T' ); 
    // Private key of a TEST address!       
    $wk->setSeed('fence twenty camera kid property acid original mixed dolphin cousin finish nominee unfold start utility');

    $msg = $this->str_with_length('WavesWalletAuthentication').$this->str_with_length('localhost').$this->str_with_length('test');        
    log_message('Info', "Message: {$msg}");
    // converto to bytes

    // Signing message with WAVESKIT
    $signedbywaveskit=$wk->sign($msg);        
    log_message('Info', 'WAVESKEEPER Signed message: ' . $wk->Base58Decode($signature));
    log_message('Info', 'WAVESKIT Signed message: ' . $signedbywaveskit);

    $waveskeepersignatureisok = $wk->verify($wk->Base58Decode($signature), $msg, $wk->Base58Decode($publickey));
    $waveskitsignatureisok = $wk->verify($signedbywaveskit, $msg, $wk->Base58Decode($publickey));
    log_message('Info', "WavesKeeper Signature OK: {$waveskeepersignatureisok}");
    log_message('Info', "WavesKit Signature OK: {$waveskitsignatureisok}");

虽然 Waveskit 签名检查正常,但从 WAVESKEEPER 传递的签名不正确:这是日志:

INFO - 2019-07-28 07:24:13 --> Message: 19000000WavesWalletAuthentication09000000localhost04000000test
INFO - 2019-07-28 07:24:15 --> WAVESKEEPER Signed message: Á‡c·Žq´lž„L­KÏò°aЉª1S‘Þ*¢$ÛSÏóT”Õ;QrxͦýôÝðxBÃÉ›ŸÔqÒÆÂ?ä‚
INFO - 2019-07-28 07:24:15 --> WAVESKIT Signed message: ýÐÒ³‡Ú“ÜåuDØyrG[¤bÖ¨Ó˜i™ecIóÒ’ìÈãZb
w,š• ­üÁ¿\ §ìíÀäáþ¹‡
INFO - 2019-07-28 07:24:20 --> WavesKeeper Signature OK: 
INFO - 2019-07-28 07:24:20 --> WavesKit Signature OK: 1

我认为问题出在要签名的数据以及我如何连接字符串长度(以字节为单位),有什么帮助吗?

刚检查的示例来自:https://docs.wavesplatform.com/en/waves-api-and-sdk/client-api/auth-api.html

工作正常:

$wk = new WavesKit();
$msg = pack( 'n', strlen( 'WavesWalletAuthentication' ) ) . 'WavesWalletAuthentication';
$msg .= pack( 'n', strlen( 'example.com' ) ) . 'example.com';
$msg .= pack( 'n', strlen( '0123456789abc' ) ) . '0123456789abc';    
$verified = $wk->verify( 
    $wk->base58Decode( '2w7QKSkxKEUwCVhx2VGrt5YiYVtAdoBZ8KQcxuNjGfN6n4fi1bn7PfPTnmdygZ6d87WhSXF1B9hW2pSmP7HucVbh' ),
    $msg,
    $wk->base58Decode( '2M25DqL2W4rGFLCFadgATboS8EPqyWAN3DjH12AH5Kdr' ) );