How to use the @grpc/grpc-js.credentials.combineChannelCredentials function in @grpc/grpc-js

To help you get started, we’ve selected a few @grpc/grpc-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LN-Zap / node-lnd-grpc / src / service.js View on Github external
const waitTime = Number.isFinite(waitForCert) ? waitForCert : FILE_WAIT_TIMEOUT
        await waitForFile(cert, waitTime)
      }

      // Create ssl credentials to use with the gRPC client.
      let creds = await createSslCreds(cert)

      // Add macaroon to credentials if service requires macaroons.
      if (this.useMacaroon && macaroon) {
        // Wait for the macaroon to exist (this can take some time immediately after Initializing a wallet).
        if (waitForMacaroon) {
          const waitTime = Number.isFinite(waitForMacaroon) ? waitForMacaroon : FILE_WAIT_TIMEOUT
          await waitForFile(macaroon, waitTime)
        }
        const macaroonCreds = await createMacaroonCreds(macaroon)
        creds = credentials.combineChannelCredentials(creds, macaroonCreds)
      }

      // Set custom connection options.
      defaultsDeep(creds.connectionOptions, connectionOptions)

      // Create a new gRPC client instance.
      const rpcService = rpc[protoPackage][this.serviceName]
      this.service = new rpcService(host, creds)

      // Wait up to CONNECT_WAIT_TIMEOUT seconds for the gRPC connection to be established.
      await promisifiedCall(this.service, this.service.waitForReady, getDeadline(CONNECT_WAIT_TIMEOUT))

      // Set up helper methods to proxy service methods.
      this.wrapAsync(rpcService.service)
    } catch (e) {
      this.debug(`Unable to connect to ${this.serviceName} service`, e)
github LN-Zap / zap-desktop / services / grpc / grpcService.js View on Github external
// Load gRPC package definition as a gRPC object hierarchy.
    const packageDefinition = await load(filepath, grpcOptions)
    const rpc = loadPackageDefinition(packageDefinition)

    // Create ssl credentials to use with the gRPC client.
    let creds = await createSslCreds(cert)

    // Add macaroon to crenentials if service requires macaroons.
    if (useMacaroon) {
      // If we are trying to connect to the internal lnd, wait up to 20 seconds for the macaroon to be generated.
      if (waitForMacaroon) {
        await waitForFile(macaroon, 20000)
      }
      const macaroonCreds = await createMacaroonCreds(macaroon)
      creds = credentials.combineChannelCredentials(creds, macaroonCreds)
    }

    // Create a new gRPC client instance.
    this.service = new rpc.lnrpc[this.serviceName](host, creds)

    try {
      // Wait up to 10 seconds for the gRPC connection to be established.
      return await promisifiedCall(this.service, this.service.waitForReady, getDeadline(10))
    } catch (e) {
      grpcLog.warn(`Unable to connect to ${this.serviceName} service`, e)
      this.service.close()
      throw e
    }
  }