rust-bitcoin/rust-secp256k1

Missing methods to work with byte representations of `ElligatorSwiftSharedSecret`

Closed this issue · 8 comments

I'm unfamiliar with the domain, so maybe there's a reason why they're not there, but looking at SharedSecret there are a bunch of methods that seem to be useful for ElligatorSwiftSharedSecret as well:

There's been a request for at least the secret_bytes method.

Oh, that's a serious oversight! We should fix this ASAP.

But at least I can think of a workaround you can use until we release the fix:

use arrayvec::ArrayVec; // can work with `Vec` too, just slower and less convenient when converting to array.
struct PseudoHasher(ArrayVec<u8, 64>);

impl core::hash::Hasher for PseudoHasher {
    fn finish(&self) -> u64 { panic!("should not call this") }
    fn write(&mut self, bytes: &[u8]) {
        self.0.extend_from_slice(bytes);
    }
}

let mut hasher = PseudoHasher(Default::default());
core::hash::Hash::hash(&shared_secret, &mut hasher);
let secret_bytes = hasher.into_inner().unwrap();
lorbax commented

Thank you @cafce25 for opening the issue. Actually, I am implementing ElligatorSwift encoding for Stratum v2 protocol handshake and I couldn't figure out why there wasn't a method like secret_bytes.
I'll try the workaround suggested by @Kixunil.
Thank you!

@lorbax usually a missing method means you shouldn't do something, so I started digging into the code and found it must be an oversight. I hope we can get an early release soon so that you guys don't have to use that horrible hack for too long.

Yep, pretty confident this was an oversight.

And LOL @ the hack where you use Hash to extract the data.

lorbax commented

@Kixunil yes usually "if there isn't this method, then there shouldn't be this method", but there wasno way for extracting the inner bytes (except from the hack). Thank you for the collaboration!

lorbax commented

Thank you @cafce25 for opening the issue. Actually, I am implementing ElligatorSwift encoding for Stratum v2 protocol handshake and I couldn't figure out why there wasn't a method like secret_bytes.
I'll try the workaround suggested by @Kixunil.
Thank you!

You can now upgrade to 0.28.2.