solana-labs / solana-web3.js

Solana JavaScript SDK
https://solana-labs.github.io/solana-web3.js
MIT License
2.11k stars 845 forks source link

Suggestion: drop node 16 (and the node-fetch and ed25519 polyfills) #1680

Open mikemaccana opened 11 months ago

mikemaccana commented 11 months ago

Motivation

node 16 is already end of life. Current web3.js includes polyfills for fetch and for Ed25519 in global.crypto. Current supported versions of node have both fetch and (from SL on Twitter) Ed25519 support.

Details

Downsides:

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@solana/web3.js@2.0.0',
npm WARN EBADENGINE   required: { node: '>=18.0.0' },
npm WARN EBADENGINE   current: { node: 'v16.6.0', npm: '9.8.1' }
npm WARN EBADENGINE }

Upsides:

engines in the package.json can be used to specify minimum node versions.

  "engines": {
    "node": ">=18.0.0"
  },
steveluscher commented 11 months ago

I'm a huge fan of making Node LTS+ the requirement, I added this in few packages but seem to have missed some others.

"engine": {
  "node": ">=17.4"
},

I don't know that there's much benefit at this point to churning everyone on the current web3.js. Might as well churn the API and the Node requirement all at once.

mcintyre94 commented 11 months ago

What about browsers though?

On the latest Chrome this is an error:

await window.crypto.subtle.generateKey('Ed25519', false, ['sign'])
Uncaught DOMException: Failed to execute 'generateKey' on 'SubtleCrypto': Algorithm: Unrecognized name

Seems to be behind a feature flag on Chrome: https://chromestatus.com/feature/4913922408710144

Caniuse doesn't seem to have this nuance, but from a quick check Firefox also doesn't work, Safari does.

steveluscher commented 11 months ago

When you try to use generateKeyPair() in the new library, the error message tells you to install and import @solana/webcrypto-ed25519-polyfill.

https://github.com/solana-labs/solana-web3.js/blob/7adc22b1a57cff867d2f735301725dc6384c3e5e/packages/assertions/src/subtle-crypto.ts#L46-L56