-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
使用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)));
}
}Metadata
Metadata
Assignees
Labels
No labels