Skip to content

[Feature Request] WsProvider mTLS support - SecureContextOptions - Node.js #5391

Open
@agilenc

Description

@agilenc
  • I'm submitting a ...
  • Bug report
  • Feature request
  • Support request
  • Other
  • Please tell us about your environment:
  • Node.js
  • Browser
  • Other (limited support for other environments)
  • What is the current behavior?

On Node when creating a new WsProvider there is no way to specify ca/cert/key (for mTLS).

  • What is the expected behavior?

Similar to the ws package where we can do:

const options: SecureContextOptions = {
  ca: fs.readFileSync('ca.crt'),
  cert: fs.readFileSync('client.crt'),
  key: fs.readFileSync('client.crt.key'),
};
const wsClient = new WebSocket('wss://hostname', options);

It would be great to be able to specify a SecureContextOptions object to the constructor when creating a new WsProvider.

  • What is the motivation for changing the behavior?

Support more use-cases, currently we are unable to use polkadot-js api because the ws client cannot connect to a secure endpoint with mTLS. Using mTLS is a requirement in our case. We only need this on Node (not browser or other env).

As a general rule client APIs that connect to nodes should provide security guarantees when possible.
This initiative would support this.

  • Implications

Talked to @TarikGul who shared this issue #5279. One comment is:

As an aside, due to the overwhelming popularity of ws vs websocket, the polyfill will also be swapped to thatws for Node environments. It has no header support. (Not sure when, it has been on the radar for the last 6 months)

To allow a SecureContextOptions object to be passed to the WsProvider constructor then here when using Node we'd first need to swap the polyfill from websocket to ws. Maybe some work has already been done in that regard?

Metadata

Metadata

Assignees

No one assigned

    Labels

    -pr appreciatedEnhancementImproves existing features or performance, making the SDK more robust and efficient.Help WantedTasks open for external contributions, suitable for independent or collaborative work.P3 - LowNon-essential improvements or minor fixes. Can be scheduled flexibly as time permits.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions