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

@turnkey/http

v2.16.0

Published

Typed HTTP client for interacting with Turnkey API

Downloads

161,630

Readme

@turnkey/http

npm

A lower-level, fully typed HTTP client for interacting with Turnkey API.

For signing transactions and messages, check out the higher-level @turnkey/ethers or @turnkey/viem signers.

Turnkey API documentation lives here: https://docs.turnkey.com.

Getting started

$ npm install @turnkey/http
import { ApiKeyStamper } from "@turnkey/api-key-stamper";
import { TurnkeyClient } from "@turnkey/http";

// This stamper produces signatures using the API key pair passed in.
const stamper = new ApiKeyStamper({
  apiPublicKey: "...",
  apiPrivateKey: "...",
});

// The Turnkey client uses the passed in stamper to produce signed requests
// and sends them to Turnkey
const client = new TurnkeyClient(
  {
    baseUrl: "https://api.turnkey.com",
  },
  stamper
);

// Now you can make authenticated requests!
const data = await client.getWhoami({
  organizationId: "<Your organization id>",
});

HTTP fetchers

@turnkey/http provides fully typed http fetchers for interacting with the Turnkey API. You can find all available methods here. The types of input parameters and output responses are also exported for convenience.

The OpenAPI spec that generates all fetchers is also included in the package.

withAsyncPolling(...) helper

All Turnkey mutation endpoints are asynchronous (with the exception of private key-related signing endpoints, e.g. /submit/sign_transaction, /submit/sign_raw_payload). To help you simplify async mutations, @turnkey/http provides a withAsyncPolling(...) wrapper. Here's a quick example:

import { withAsyncPolling, TurnkeyActivityError } from "@turnkey/http";

// Use `withAsyncPolling(...)` to wrap & create a fetcher with built-in async polling support
const fetcher = withAsyncPolling({
  request: client.createPrivateKeys,
});

// The fetcher remains fully typed. After submitting the request,
// it'll poll until the activity reaches a terminal state.
try {
  const activity = await fetcher({
    body: {
      /* ... */
    },
  });

  // Success!
  console.log(
    activity.result.createPrivateKeysResultV2?.privateKeys?.[0]?.privateKeyId
  );
} catch (error) {
  if (error instanceof TurnkeyActivityError) {
    // In case the activity is rejected, failed, or requires consensus,
    // a rich `TurnkeyActivityError` will be thrown. You can read from
    // `TurnkeyActivityError` to find out why the activity didn't succeed.
    //
    // For instance, if your activity requires consensus and doesn't have
    // enough approvals, you can get the `activityId` from `TurnkeyActivityError`,
    // store it somewhere, then re-fetch the activity via `.postGetActivity(...)`
    // when the required approvals/rejections are in place.
  }
}

More examples

See createNewEthereumPrivateKey.ts in the with-ethers example.

See also