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

fix: ledger sig conversion #390

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions crypto/ledger_secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,23 @@ func convertDERtoBER(signatureDER []byte) ([]byte, error) {
if err != nil {
return nil, err
}
sig := sigDER.Serialize() // 0x30 <total length> 0x02 <length of R> <R> 0x02 <length of S> <S>
r := new(big.Int).SetBytes(sig[4:36])
s := new(big.Int).SetBytes(sig[38:70])

// Total length of returned signature is 1 byte for each magic and length
// (6 total), plus lengths of R and S.
// totalLen := 6 + len(canonR) + len(canonS)
// b := make([]byte, 0, totalLen)
// b = append(b, asn1SequenceID)
// b = append(b, byte(totalLen-2))
// b = append(b, asn1IntegerID)
// b = append(b, byte(len(canonR)))
// b = append(b, canonR...)
// b = append(b, asn1IntegerID)
// b = append(b, byte(len(canonS)))
// b = append(b, canonS...)
sig := sigDER.Serialize()
lenOfR := int(sig[3])
r := new(big.Int).SetBytes(sig[4 : 4+lenOfR])
s := new(big.Int).SetBytes(sig[4+lenOfR+2:])
sigBER := tmbtcec.Signature{R: r, S: s}
return sigBER.Serialize(), nil
}
Expand Down
Loading