2.10.0 • Published 29 days ago

@turnkey/http v2.10.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
29 days ago

@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 TurnkeyApi.getWhoami({
  body: {
    organizationId: "...",
  },
});

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

2.10.0

29 days ago

2.9.1

2 months ago

2.9.0

2 months ago

2.8.0

2 months ago

2.7.0

3 months ago

2.7.1

3 months ago

2.6.2

4 months ago

2.6.1

5 months ago

2.6.0

5 months ago

2.5.1

5 months ago

2.5.0

5 months ago

2.4.1

5 months ago

2.4.0

5 months ago

2.4.2

5 months ago

1.2.0

8 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.1

9 months ago

1.0.0

10 months ago

1.3.0

7 months ago

2.3.0

6 months ago

0.18.1

10 months ago

2.2.0

6 months ago

2.3.1

6 months ago

2.1.0

7 months ago

2.0.0

7 months ago

0.18.0

10 months ago

0.17.0

11 months ago

0.17.1

11 months ago

0.11.0

1 year ago

0.12.0

12 months ago

0.13.0

12 months ago

0.14.0

12 months ago

0.13.1

12 months ago

0.15.0

11 months ago

0.13.2

12 months ago

0.16.0

11 months ago

0.9.0-beta.0

1 year ago

0.10.0

1 year ago

0.8.0-beta.0

1 year ago

0.8.1-beta.0

1 year ago

0.8.0-beta.1

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.7.1-beta.0

1 year ago

0.5.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago