Closed decentralgabe closed 1 year ago
There is the SignCompact
function which I believe returns what you are asking for: https://github.com/decred/dcrd/blob/master/dcrec/secp256k1/ecdsa/signature.go#L765. That returns a byte slice of <compactSigRecoveryCode><32-byte R><32-byte S>
. So all you probably need to do is to remove that first byte with the recovery code and it should be compatible with the TS lib you linked to (if I understand their documentation correctly).
thanks @guggero would you be open to a PR to add a new .SerializeCompactHex
method here?
I don't think you can do it in this repo, since the Signature
struct lives in the decred/dcrd
repo and you won't have access to the non-exported r
and s
values. So I think just using SignCompact
is probably your best option.
thanks, you're right. I tried your suggestion and it worked.
I am attempting to build compatibility of secp256k1 signatures between typescript and golang. A prominent TS lib is noble-secp256k1 which exposes an option to sign/encode using DER.
The only way the library exposes transforming a secp256k1 signature into
[]byte
is via the [Serialize
method]() which serializes to the DER format.It would be great if an enhancement could be made to serialize without the DER format, as it's not always needed. More broadly, it appears this functionality is missing in the go ecosystem. This library remains the most authoritative option for secp256k1 usage and rightly so, and it can be improved to enable non-DER serializations.
If this is possible today and I've misunderstood please help me learn how to serialize to bytes without DER.