Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubKeyInfo类的getAddress方法没有判断publicKey的前缀,3.0版本的SDK获取address会出现问题。 #32

Open
limingxie opened this issue Apr 23, 2024 · 0 comments

Comments

@limingxie
Copy link
Contributor

limingxie commented Apr 23, 2024

使用mnemonicService.generatePrivateKeyByMnemonic方法创建PkeyInfo对象后,
pkeyInfo.getPublicKey().getAddress()会获得错误的address
因为 PubKeyInfo的getAddress方法没有判断前缀直接截取的publicKey所以SDK 3.0版本获得的Address是错误的。

public String getAddress(){
    EccTypeEnums eccTypeEnums = EccTypeEnums.getEccByName(eccName);
    CryptoKeyPair cryptoKeyPair = KeyUtils.getCryptKeyPair(eccTypeEnums);
    return Numeric.toHexString(cryptoKeyPair.getAddress(Arrays.copyOfRange(publicKey,1,publicKey.length))); //这里直接截取了
}

//添加了PubKey的长度判断
==>
public String getAddress(){
    EccTypeEnums eccTypeEnums = EccTypeEnums.getEccByName(eccName);
    CryptoKeyPair cryptoKeyPair = KeyUtils.getCryptKeyPair(eccTypeEnums);
    if (Numeric.toHexString(publicKey).length() == CryptoKeyPair.PUBLIC_KEY_LENGTH_IN_HEX){
        return Numeric.toHexString(cryptoKeyPair.getAddress(publicKey));
    } else {
        return Numeric.toHexString(cryptoKeyPair.getAddress(Arrays.copyOfRange(publicKey,1,publicKey.length)));
    }
}
@limingxie limingxie changed the title PubKeyInfo类的getAddress方法没有判断publicKey的前缀,特定场景获取address会出现问题。 PubKeyInfo类的getAddress方法没有判断publicKey的前缀,3.0版本的SDK获取address会出现问题。 Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant