paulmillr / noble-curves

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

Add pure annotation to all calls to `twistedEdwards` #62

Closed steveluscher closed 1 year ago

steveluscher commented 1 year ago

This PR makes it so that if you only use one export:

import { ed25519 } from '@noble/curves`;

…then only the twistedEdwards call that constructs that export will remain after bundling and tree-shaking.

Before

Before this change, the compiled bundle contains all the code that constructs ed25519ph and ed25519ctx remains.

var ed25519 = twistedEdwards(ed25519Defaults);
function ed25519_domain(data, ctx, phflag) {
  if (ctx.length > 255)
    throw new Error("Context is too big");
  return concatBytes(utf8ToBytes("SigEd25519 no Ed25519 collisions"), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
}
twistedEdwards({ ...ed25519Defaults, domain: ed25519_domain });
twistedEdwards({
  ...ed25519Defaults,
  domain: ed25519_domain,
  prehash: sha512
});

After

var ed25519 = twistedEdwards(ed25519Defaults);
steveluscher commented 1 year ago

This is similar to https://github.com/paulmillr/noble-hashes/pull/67, which I'm really looking forward to being released, since it will let us tree-shake away the sha512_224, sha512_256, and sha384 exports that we don't use.

paulmillr commented 1 year ago

I'm really looking forward to being released

The exports are 15 lines of code. It's really not a big deal for any app. I think the release can wait until our ordinary release schedule, which is one release every month or two.

Every new release complicates amount of possible versions in use so I'd rather make slow releases instead.