cryptography – Derive Secp256k1 curve public key beginning off from identified 32 bytes string

0
62


Beginning off from a sha256 hash of a threshold pubkey, how can I generate a legitimate secp256k1 public key?

The problem is that the 32 bytes of the hash doesn’t at all times fall inside secp256k1 vary, so I think I might want some further elliptic curve operation on the hash to convey it get to a byte string I can use to generate a legitimate pubkey.

To this point I’ve tried taking a modulus of the hash towards fixed secp256k1 curve order. Did not work, in all probability as a result of I do not totally perceive the elliptic curve math vital right here…

/// Rust 
/// 
/// Converts a federation id to a public key to which we do not know the
/// non-public key
///
/// That's okay as a result of we solely use it for including a route
/// trace to LN invoices that tells fedimint shoppers that the bill can
/// solely be paid internally. Since no LN node with that pb key can exist
/// different LN senders will know that they can not pay the bill.
pub fn to_fake_ln_pub_key(seed: threshold_crypto::PublicKey) -> anyhow::Consequence<secp256k1::PublicKey> {
    let mut bytes = [0u8; 33];
    bytes[0] = 0x02;

    let modulus = BigUint::from_bytes_be(
        &<Sha256 as bitcoin_hashes::Hash>::hash(&seed).into_inner(),
    ) % BigUint::from_bytes_be(&secp256k1::constants::CURVE_ORDER);

    bytes[1..].copy_from_slice(&modulus.to_bytes_be());

    Okay(secp256k1::PublicKey::from_slice(&bytes)?)
}

Motivation and Context:

The pubkey I am trying to generate on this method will likely be used as a supply node id marker in a legitimate bill that’s solely payable between shoppers inside a Fedimint federation. On this state of affairs, the brink pubkey we use as ‘seed information’ is definitely the federation ID.

One consumer inside a federation would generate a lightning bill, including a route trace with supply node id set to this pubkey we want to generate.

One other consumer inside the federation trying to pay this bill ought to be capable to generate an identical pubkey marker from federation id threshold pubkey, and match it towards the marker.

With this marker, they’ll do a transaction between themselves inside the federation with out ever going over the lightning community.

Ref:

LEAVE A REPLY

Please enter your comment!
Please enter your name here