fix(signing): use .toCompactRawBytes() for SECP256K1 signatures#1
Open
amathxbt wants to merge 1 commit into
Open
fix(signing): use .toCompactRawBytes() for SECP256K1 signatures#1amathxbt wants to merge 1 commit into
amathxbt wants to merge 1 commit into
Conversation
In noble/curves v2, secp256k1.sign() returns a Signature object, not a Uint8Array. The previous code cast it directly as unknown as Uint8Array, which serialises the object structure rather than the compact (r,s) bytes. Result: every SECP256K1 / ETHSECP256K1 signature produced by this SDK is invalid — the node rejects all transactions signed with those curves. Fix: call .toCompactRawBytes() on the returned Signature object to get the correct 64-byte compact representation before passing to bytesToHex.
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.
Bug
secp256k1.sign()in@noble/curvesv2 returns aSignatureobject, not aUint8Array. The original code cast it asunknown as Uint8Arrayand passed the object directly tobytesToHex.bytesToHexiterates bytes of whatever it receives; operating on a JavaScript object instead of typed bytes produces garbage hex for every SECP256K1 and ETHSECP256K1 signature generated by this SDK.Impact: All transactions signed with SECP256K1 or ETHSECP256K1 keys are rejected by the network — the signature bytes are wrong.
Fix
Call
.toCompactRawBytes()on the returnedSignatureobject to obtain the correct 64-byte compact (r, s) representation before encoding.This matches how
@noble/curvesis documented and used for ed25519 (which already calls.sign()and gets aUint8Arraydirectly — ed25519 returns bytes, secp256k1 does not).