bugfix: sm2生成address时,go sdk与java sdk生成结果不一致。 - #293
Open
imloama wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an inconsistency in address generation between the Go and Java SDKs by ensuring that the public key’s X and Y coordinates are zero-padded to a fixed length.
- Added padding logic for X coordinate
- Added padding logic for Y coordinate
| copy(pubBytes[publicKeyLength/2:], pub.Y.Bytes()) | ||
| // 确保X坐标长度固定,不足时在前端补0 | ||
| xBytes := pub.X.Bytes() | ||
| copy(pubBytes[:publicKeyLength/2-(len(xBytes))], make([]byte, publicKeyLength/2-len(xBytes))) |
There was a problem hiding this comment.
[nitpick] The padding logic for both X and Y coordinates is similar. Consider extracting this repeated logic into a helper function to enhance maintainability.
Contributor
|
谢谢你的贡献,能否请您添加一个单元测试,验证这个问题? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
在生成随机地址时,出现公钥补0,导致生成的地址和java端不一致。从而操作资产时,出现错误。
如私钥地址:0xcb2703a0030898e676e4bacaa1d0d1f12ad6a4db3a3eb1e65e4d4710e31bdb02
go sdk生成地址:0x46a9bc34c51ad531079f7ba0c6f0e4c6b6ed85df
java sdk生成地址:0xa8c9f1fe39d16a54fe1745bbd762d837e8330620
修改后,生成一致