npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lobstrco/signer-extension-api

v1.0.0-beta.0

Published

Utility functions to interact with LOBSTR extension

Downloads

867

Readme

@lobstrco/signer-extension-api

This packages builds a wrapper around the messaging system used to interact with the LOBSTR browser extension. Client applications will be able to install this package from npm and then integrate with the LOBSTR signer extension using dev-friendly methods.

Getting Started

To get started, you’ll need both the LOBSTR signer extension and the API needed to integrate with it.

Install the LOBSTR signer extension.

You’ll require a local version of the extension to test.

  • Head over to the Chrome Web Store and install LOBSTR signer extension into your browser.

Install LOBSTR signer extension API

Now, you need a way to communicate with the LOBSTR signer extension. To facilitate this, we created a Javascript library called @lobstrco/signer-extension-api that will let you send and receive messages from the extension.

For ES2023 applications

  • Install the module using npm: npm install @lobstrco/signer-extension-api

or

  • Install the module using yarn: yarn add @lobstrco/signer-extension-api

For browser-based applications

Install the packaged library via script tag using cdnjs, swapping in the desired version number for {version}:

<script src="https://cdnjs.cloudflare.com/ajax/libs/lobstrco-signer-extension-api/{version}/index.min.js"></script>

Using LOBSTR signer extension in a web app

You now have an extension installed on your machine and a library to interact with it. This library will provide methods to send and receive data from a user’s extension on your website or application.

Importing

First import the whole library in an ES2023 application

import lobstrApi from "@lobstrco/signer-extension-api";

or import just the modules you require:

import {
 isConnected,
 getPublicKey,
 signTransaction,
} from "@lobstrco/signer-extension-api";

Now let's dig into what functionality is available to you:

isConnected

isConnected() -> <Promise<boolean>>

This function is used to determine whether a user has the LOBSTR signer extension installed in your application.

import { isConnected } from "@lobstrco/signer-extension-api";

if (await isConnected()) {
  alert("User has LOBSTR extension installed!");
}

getPublicKey

getPublicKey() -> <Promise<string>>

If the LOBSTR wallet app is installed, the LOBSTR signer extension will simply return the public key. If either of the above is not true, it will return an empty string.

import { getPublicKey } from "@lobstrco/signer-extension-api";

const retrievePublicKey = async (): Promise<string> => {
  let publicKey = "";
  let error = "";

  try {
    publicKey = await getPublicKey();
  } catch (e) {
    error = e;
  }

  if (error) {
    return error;
  }

  return publicKey;
};

signTransaction

signTransaction(xdr: string) -> <Promise<string>>

This function accepts a transaction XDR string, which it will decode, sign as the user, and then return the signed transaction to your application.

NOTE: The user must provide a valid transaction XDR string for the extension to properly sign.

import { signTransaction } from "@lobstrco/signer-extension-api";

const userSignTransaction = async (xdr: string): Promise<string> => {
  let signedTransaction = "";
  let error = "";

  try {
    signedTransaction = await signTransaction(xdr);
  } catch (e) {
    error = e;
  }

  if (error) {
    return error;
  }

  return signedTransaction;
};

Using LOBSTR in the browser

You now have the LOBSTR signer extension installed on our machine and a library to interact with it. This library will provide you methods to send and receive data from a user’s extension in your website or application.

Importing

First import the library in the <head> tag of your page.

  • Install the packaged library via script tag using cdnjs, swapping in the desired version number for {version}
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lobstrco-signer-extension-api/{version}/index.min.js"></script>
</head>

This will expose a global variable called window.lobstrSignerExtension that will contain our library.

The call signatures will be exactly the same as the node version, but you will call the methods directly from window.lobstrSignerExtensionApi:

For example:

if (await window.lobstrSignerExtensionApi.isConnected()) {
  alert("User has LOBSTR extension installed!");
}