Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pure annotation to all calls to twistedEdwards #62

Merged
merged 1 commit into from
Jul 1, 2023
Merged

Add pure annotation to all calls to twistedEdwards #62

merged 1 commit into from
Jul 1, 2023

Conversation

steveluscher
Copy link
Contributor

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);

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

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

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

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

```js
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
});
```

```js
var ed25519 = twistedEdwards(ed25519Defaults);
```
@steveluscher
Copy link
Contributor Author

This is similar to paulmillr/noble-hashes#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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants