Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rebase-client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rebase-client

This Rust-to-WASM compiled library is a thin wrapper around the client portion of the [Rebase Witness SDK](https://github.com/spruceid/rebase/tree/main/rust/rebase_witness_sdk). It makes several design choices that make usage in WASM easier.

  • 0.4.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Rebase Client

This Rust-to-WASM compiled library is a thin wrapper around the client portion of the Rebase Witness SDK. It makes several design choices that make usage in WASM easier.

Install

$ npm i @rebase-xyz/rebase-client

Rust implementation

The Client struct exposed by the library (and made available to JavaScript consumers) has an implementation that looks like:

#[wasm_bindgen]
impl Client {
    #[wasm_bindgen(constructor)]
    pub fn new(
        instructions: String,
        statement: String,
        jwt: Option<String>,
        ld: Option<String>,
    ) -> Result<Client, String> {

        // ...
    }

    pub fn instructions(&self, req: String) -> Promise {
        // ...
    }

    pub  fn statement(&self, req: String) -> Promise {
        // ...
    }

    pub fn jwt(&self, req: String) -> Promise {
        // ...
    }

    pub fn ld(&self, req: String) -> Promise {
        // ...
    }
}

Once the client is instanciated, the user simply has to pass in reqs that conform to JSON stringified requests described in detail here, where the resulting Promise contains a JSON stringified responses described in the linked doc.

JavaScript Usage

Concrete usage of this library in JS is found here. The client's constructor accepts up to three urls assumed to be pointed at a witness service created using the library found here. The first URL expected is for statement generation, the second is for JWT credential generation, and the third for LD credential generation.

The statement URL is required and at least one of the two optional URLs must be provided. All of the following would be valid:

import { Client } from "@rebase-xyz/rebase-client";

const statementUrl = "https://example.com/statement";
const instructionsUrl = "https://example.com/instructions";
const jwtUrl = "https://example.com/witness/jwt";
const ldUrl = "https://example.com/witness/ld";

let client = new Client(instructionsUrl, statementUrl, jwtUrl);
client = new Client(instructionsUrl, statementUrl, jwtUrl, null);
client = new Client(instructionsUrl, statementUrl, null, ldUrl);
client = new Client(instructionsUrl, statementUrl, jwtUrl, ldUrl);

All of the following (and more!) would be invalid.

client = new Client();
client = new Client(null, null);
client = new Client(null, null, null, null);
client = new Client(null, statementUrl, jwtUrl, null);
client = new Client(instructionsUrl, null, jwtUrl, null);
client = new Client(null, null, jwtUrl);
client = new Client(null, statementUrl, jwtUrl, ldUrl);
client = new Client(instructionsUrl, null, jwtUrl, ldUrl);
client = new Client(instructionsUrl, statementUrl, null, null);

Once a valid client has been constructed, it can be used like so (where req is a JSON stringified valid request):

let res = await client.statement(req);

This would produce a JSON stringified version of the StatementRes found here. Instructions requests work the same way and produce output found here.

let jwtRes = await client.jwt(req);
let ldRes = await client.ld(req);

A corresponding jwtUrl or ldUrl must be provided at config time to use jwt and ld methods. These would both produce a JSON stringified version of the WitnessJWTRes/WitnessLDRes found here

FAQs

Package last updated on 21 Oct 2022

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