paulmillr / noble-curves

Audited & minimal JS implementation of elliptic curve cryptography.
https://paulmillr.com/noble
MIT License
623 stars 56 forks source link

cannot use `finalExponentiate` with type safety #65

Closed CluEleSsUK closed 12 months ago

CluEleSsUK commented 12 months ago

In https://github.com/drand/drand-client we use the bls12-381 curve for verifying signatures created by our network. We have a custom scheme that creates signatures on G1 rather than G2, and thus far have been performing our own pairing operations as demonstrated here.

With the newest curves version, it appears that finalExponentiate is on the type Fp12Utils here which is available on the CurveType type, which gets passed into the bls constructor here. Unfortunately, as defines its own fields param, we can't use the finalExponentiate function directly, without casting to any. Other types we could cast it to are private, but even then casting feels a little ugly.

Is there another suggested way to use finalExponentiate directly or would it be possible to expose it?

Thanks for all your hard work! Your libraries have saved us a lot of pain!

paulmillr commented 12 months ago

Could you please describe what you've said in a few lines of code, to make it easier for me to understand?

CluEleSsUK commented 12 months ago

To use the finalExponentiate, one must do:

    const Fp12 = bls.fields.Fp12 as any;// as {finalExponentiate(num: any): any;};
    const exp = Fp12.finalExponentiate(bls.fields.Fp12.mul(eGS, ePHm));

We identified that we could just pass a flag to the pairing operation like so: bls.pairing(S, G, true) so this could probably be closed (unless others want to use the finalExponentiate separately from pairing for some reason)

paulmillr commented 12 months ago

updated docs 6220534