fix: use canonical DER encoding for WebCrypto ECDSA signatures#240
Merged
ajhodges merged 3 commits intobase:masterfrom Jan 29, 2026
Merged
fix: use canonical DER encoding for WebCrypto ECDSA signatures#240ajhodges merged 3 commits intobase:masterfrom
ajhodges merged 3 commits intobase:masterfrom
Conversation
Collaborator
✅ Heimdall Review Status
|
montycheese
approved these changes
Jan 29, 2026
Collaborator
montycheese
left a comment
There was a problem hiding this comment.
verified works locally, thanks for finding this!
| authenticatorData: arrayBufferToBase64Url(hexToBytes(webauthn.authenticatorData)), | ||
| clientDataJSON: arrayBufferToBase64Url(stringToBytes(webauthn.clientDataJSON)), | ||
| signature: arrayBufferToBase64Url(asn1EncodeSignature(signatureRaw.r, signatureRaw.s)), | ||
| signature: arrayBufferToBase64Url(Signature.toDerBytes(signatureRaw)), |
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.
Summary
Fixed a bug where WebCrypto ECDSA signatures were incorrectly DER-encoded, causing Go's strict
encoding/asn1parser to reject them.The custom
asn1EncodeSignaturefunction didn't add the required0x00padding byte when an INTEGER's first byte has its high bit set (≥ 0x80). In DER encoding, this padding is mandatory to indicate the value is positive—without it, parsers interpret the value as negative.Changes:
asn1EncodeSignaturewith Ox'sSignature.toDerByteswhich produces canonical DER encodingasn1EncodeSignaturefunction and its unused importsHow did you test your changes?
Added unit tests in
encoding.test.tsthat verify:0x00padding is added when r has high bit set (e.g.,0x8e...)0x00padding is added when s has high bit set (e.g.,0xca...)0x6e...,0x4a...)Tests fail with the old implementation (missing required padding) and pass with the fix.
Also ran playground locally and made a few cryptokey transactions via http://localhost:3001/add-sub-account, which seemed to work fine