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

@xdbchain/xdbwallet-api

v1.0.0

Published

Utility functions to interact with XDB Wallet web extension

Downloads

5

Readme

XDB Wallet API

This package builds a wrapper around the messaging system used to interact with the XDB Wallet wallet (a web browser extension). Client applications will be able to install this package from npm and then integrate with XDB Wallet using dev-friendly methods like getPublicKey.

Both the XDB Wallet web extension and XDB Wallet API are built to support transactions on the XDB Chain blockchain network.

Using this package

Importing

import xdbwalletApi from "@xdbchain/xdbwallet-api";

or import just the modules you require:

import {
  isConnected,
  getPublicKey,
  signTransaction,
  getNetwork,
} from "@xdbchain/xdbwallet-api";

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

isConnected

isConnected() -> <Promise<boolean>>

This function is useful for determining if a user in your application has XDB Wallet installed.

import { isConnected } from "@xdbchain/xdbwallet-api";

if (await isConnected()) {
  alert("User has XDB Wallet!");
}

getPublicKey

getPublicKey() -> <Promise<string>>

If the user has authorized your application previously and XDB Wallet is connected, XDB Wallet will simply return the public key. If either one of the above is not true, it will return an empty string.

import { getPublicKey } from "@xdbchain/xdbwallet-api";

const retrievePublicKey = async () => {
  let publicKey = "";
  let error = "";

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

  if (error) {
    return error;
  }

  return publicKey;
};

const result = retrievePublicKey();

getNetwork

getNetwork() -> <Promise<string>>

This function is useful for determining what network the user has configured XDB Wallet to use.

import {
  isConnected,
  getNetwork,
} from "@xdbchain/xdbwallet-api";

if (await isConnected()) {
  alert("User has XDB Wallet!");
}

const retrieveNetwork = async () => {
  let network = "";
  let error = "";

  try {
    network = await getNetwork();
  } catch (e) {
    error = e;
  }

  if (error) {
    return error;
  }

  return network;
};

const result = retrieveNetwork();

signTransaction

signTransaction(xdr: string, network?: "PUBLIC" | "TESTNET") -> <Promise<string>>

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

The user will need to provide their password if the extension does not currently have their private key. Once the user has provided their password, the extension will have access to the user private key for 5 minutes. The user must then review the transaction details and accept within those 5 minutes for the transaction to be signed.

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