T-Invest Node SDK Node.js
On this page

Configure a TLS connection

Use this reference when an application connects to T-Invest or a custom gRPC server over TLS. Keep the bundled certificate for T-Invest or supply a Buffer containing the application's root certificates. The new channel can then verify the required certificate chain while the system trust store stays intact.

Connect to T-Invest with the bundled certificate

The T-Invest API in production and sandbox requires certificates from the Russian Ministry of Digital Development's national certification authority. The SDK bundles the Russian Trusted Root CA in PEM format and passes it to ChannelCredentials.createSsl() when useSsl: true.

The certificate applies only to that SDK instance's gRPC channel.

  • The system trust store stays intact.
  • The process environment stays intact, including NODE_EXTRA_CA_CERTS.
  • Installation and SDK operation use the bundled file without downloading certificates.
  • TLS continues to verify the server name.
  • The T-Invest server presents the intermediate Russian Trusted Sub CA in its chain.

See the T-Invest documentation for official endpoints and certificate requirements.

Verify where the bundled certificate comes from

Bundled Russian Trusted Root CA records the certificate's source, how to obtain it, its X.509 fingerprint, distribution details, and its path in the package.

Supply certificates for your own server

To connect to your own server or a test server, pass PEM root certificates through tls.rootCertificates. Pass the certificate contents in a Buffer. For this channel, the supplied certificates replace the bundled certificate and serve as the entire trust store. Add the standard Node.js roots yourself if needed.

custom-tls.ts
import { readFile } from 'node:fs/promises';
import { TInvestNodeSDK } from '@woodger/t-invest-node-sdk';

const rootCertificates = await readFile('./certificates/custom-root.pem');
const sdk = new TInvestNodeSDK({
  token,
  endpoint,
  tls: {
    rootCertificates
  }
});

With useSsl: false, the SDK creates a plaintext connection without loading the TLS settings or bundled PEM file.

What TLS verifies

The bundled root certificate verifies the T-Invest TLS chain. The certificate authority can also issue certificates for other servers. To pin a specific T-Bank public key with SPKI pinning, define separate rules for key verification and rotation.

See the maintainer guide for releasing the SDK with a new certificate. Update the certificate

Recognize certificate verification failures

When TLS reports an unambiguous chain validation error or server name mismatch, the SDK returns SdkErrorCode.Unavailable with source: 'tls'. The error retains the gRPC method in path and the original details and cause for diagnosis.

Ordinary provider or network UNAVAILABLE errors, including DNS failures, refused or reset connections, and timeouts, keep source: 'grpc'. The application decides when to retry based on the call and error.

The public SDK contract classifies errors by code and source. Use details and cause for diagnosis, including low-level TLS errors.