Socket
Socket
Sign inDemoInstall

@toruslabs/openlogin-jrpc

Package Overview
Dependencies
Maintainers
4
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toruslabs/openlogin-jrpc

OpenLogin is a plug & play authentication suite that combines the simplicity of passwordless authentication with the security of non-custodial public key infrastructure (PKI).


Version published
Weekly downloads
114K
increased by6.53%
Maintainers
4
Weekly downloads
 
Created

What is @toruslabs/openlogin-jrpc?

@toruslabs/openlogin-jrpc is a JavaScript library that provides JSON-RPC (Remote Procedure Call) functionalities for interacting with the OpenLogin authentication system. It allows developers to create and manage JSON-RPC connections, handle requests and responses, and integrate with the OpenLogin system for secure authentication and communication.

What are @toruslabs/openlogin-jrpc's main functionalities?

Creating a JSON-RPC connection

This feature allows you to create a JSON-RPC connection using the provided middleware and engine. The code sample demonstrates how to set up a JSON-RPC engine and create a stream for sending and receiving JSON-RPC messages.

const { createStreamMiddleware } = require('@toruslabs/openlogin-jrpc');
const { createEngineStream } = require('@toruslabs/openlogin-jrpc');
const { JsonRpcEngine } = require('@toruslabs/openlogin-jrpc');

const engine = new JsonRpcEngine();
const { middleware, stream } = createStreamMiddleware();
engine.push(middleware);
const rpcStream = createEngineStream({ engine });

// Now you can use rpcStream to send and receive JSON-RPC messages

Handling JSON-RPC requests

This feature allows you to handle JSON-RPC requests by defining middleware functions. The code sample shows how to create a middleware that responds to a specific JSON-RPC method ('example_method') with a predefined result.

const { JsonRpcEngine } = require('@toruslabs/openlogin-jrpc');

const engine = new JsonRpcEngine();

engine.push((req, res, next, end) => {
  if (req.method === 'example_method') {
    res.result = 'example_result';
    end();
  } else {
    next();
  }
});

// Now the engine can handle JSON-RPC requests with the method 'example_method'

Sending JSON-RPC requests

This feature allows you to send JSON-RPC requests and handle the responses. The code sample demonstrates how to create a JSON-RPC request and send it through the rpcStream, then handle the response.

const { createEngineStream, JsonRpcEngine } = require('@toruslabs/openlogin-jrpc');
const { createStreamMiddleware } = require('@toruslabs/openlogin-jrpc');

const engine = new JsonRpcEngine();
const { middleware, stream } = createStreamMiddleware();
engine.push(middleware);
const rpcStream = createEngineStream({ engine });

const request = { jsonrpc: '2.0', id: 1, method: 'example_method', params: [] };

rpcStream.write(request, (err, response) => {
  if (err) {
    console.error(err);
  } else {
    console.log(response.result); // 'example_result'
  }
});

Other packages similar to @toruslabs/openlogin-jrpc

FAQs

Package last updated on 26 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc