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/eip-1193-provider

v0.2.0

Published

EIP-1193 Provider for Turnkey.

Downloads

81

Readme

Turnkey EIP-1193 Provider

The @turnkey/eip-1193-provider package delivers a Turnkey-compatible Ethereum provider that adheres to the EIP-1193 standards. It's built to integrate seamlessly with a broad spectrum of EVM-compatible chains, offering capabilities like account management, transaction signing, and blockchain interaction. This initial setup is intended for use in conjunction with the @turnkey/http and @turnkey/webauthn-stamper package, for initial authentication.

Installation

Before you start using the Turnkey EIP-1193 Provider, make sure to install the necessary packages in your project. This guide assumes you have a Node.js environment ready for development.

Install the required packages using NPM or Yarn:

npm install @turnkey/eip-1193-provider @turnkey/http @turnkey/webauthn-stamper
pnpm add @turnkey/eip-1193-provider @turnkey/http @turnkey/webauthn-stamper
yarn add @turnkey/eip-1193-provider @turnkey/http @turnkey/webauthn-stamper

Initialization

To set up the Turnkey EIP-1193 Provider, you need to initialize it with your configuration, which includes setting up the Turnkey client with your base URL and stamper.

import { WebauthnStamper } from "@turnkey/webauthn-stamper";
import { TurnkeyClient } from "@turnkey/http";

const stamper = new WebauthnStamper({
  rpId: "example.com",
});

// Initialize the Turnkey HTTP client
const turnkeyClient = new TurnkeyClient(
  { baseUrl: "https://api.turnkey.com" },
  stamper
);

// Get the organizationId of the sub-organization connected to the users account
const { organizationId } = await turnkeyClient.getWhoami({
  organizationId: process.env.ORGANIZATION_ID,
});

// Get the user wallets associated with their sub-organization
const { wallets } = await turnkeyClient.getWallets({
  organizationId,
});

// Get the walletId to connect to the provider
const walletId = wallets[0].walletId;

const chain = {
  chainName: "Ethereum Mainnet",
  chainId: "0x1",
  rpcUrls: ["https://mainnet.infura.io/v3/your-infura-project-id"],
};

// Initialize the EIP-1193 Provider with your configuration
const provider = await createEIP1193Provider({
  walletId,
  organizationId,
  turnkeyClient,
  chains: [
    chain,
    // Add more chains as needed
  ],
});

Usage

eth_requestAccounts

Requests the user to provide an Ethereum address for identification, as specified by EIP-1102. This method initiates connectivity with the client and will prompt for passkey authentication.

const accounts = await provider.request({ method: "eth_requestAccounts" });
// Logs the array accounts associated with the provided walletId & organization
console.log(accounts);

Authentication Prompt Methods

The following methods also prompt for passkey authentication:

  • personal_sign: Signs a message with the specified account.
  • eth_sign: Signs data with the specified account.
  • eth_signTransaction: Signs a transaction with the specified account.
  • eth_signTypedData_v4: Signs typed data according to EIP-712 with the specified account.
  • eth_sendTransaction: Submits a transaction to the network for execution.

Testing (Local)

  1. Copy .env.example to .env.local
cp .env.example .env
  1. Start the Anvil node in one shell:
pnpm anvil
  1. Run the tests in a new shell:
pnpm test

Contributing

We welcome contributions to improve the Turnkey EIP-1193 Provider. Please follow the project's contribution guidelines.

License

This project is licensed under LICENSE, with detailed information available in the repository.