@privy-io/cross-app-connect
Version:
Privy cross app wallet connectors for wagmi and RainbowKit
110 lines (106 loc) • 3.24 kB
TypeScript
import * as _wagmi_core from '@wagmi/core';
import * as viem from 'viem';
import { WalletDetailsParams, Wallet } from '@rainbow-me/rainbowkit';
/**
* Options for creating a wagmi connector for a Privy cross-app wallet
*/
interface CreatePrivyConnectorOptions {
/**
* The Privy app ID of the cross-app wallet provider.
*/
id: string;
/**
* Will show up as the wallet's name in RainbowKit UIs
*/
name: string;
/**
* Will show up as the wallet's image in RainbowKit UIs
*/
iconUrl: string;
/**
* @experimental Interfaces are subject to change in the future.
* Informs the wagmi connector to use the smart wallet and
* transforms the connector functions.
*/
smartWalletMode?: boolean;
}
/**
* Create a wagmi connector for the Privy cross-app wallet provider.
*
* Adapted from wagmi injected connector as a reference implementation:
* https://github.com/wevm/wagmi/blob/main/packages/core/src/connectors/injected.ts#L94
*
* @example
* import { createConfig, http } from "wagmi";
* import { mainnet } from "wagmi/chains";
*
* const privyWalletConnector = toPrivyWalletConnector({
* providerAppId: <your-app-id>,
* providerName: 'Your app',
* providerIconUrl: 'https://example.com/image.png',
* })
*
* export const wagmiConfig = createConfig({
* chains: [mainnet],
* transports: {
* [mainnet.id]: http(),
* },
* connectors: [privyWalletConnector],
* ssr: true,
* });
*/
declare function toPrivyWalletConnector(params: CreatePrivyConnectorOptions, rkDetails?: WalletDetailsParams): _wagmi_core.CreateConnectorFn<{
on: <event extends keyof viem.EIP1193EventMap>(event: event, listener: viem.EIP1193EventMap[event]) => void;
removeListener: <event extends keyof viem.EIP1193EventMap>(event: event, listener: viem.EIP1193EventMap[event]) => void;
request: viem.EIP1193RequestFn<viem.EIP1474Methods>;
}, Record<string, unknown>, Record<string, unknown>>;
/**
* Options for creating a RainbowKit wallet for a Privy cross-app wallet
*/
interface CreatePrivyWalletOptions {
/**
* The Privy app ID of the cross-app wallet provider.
*/
id: string;
/**
* Will show up as the wallet's name in RainbowKit UIs
*/
name: string;
/**
* Will show up as the wallet's image in RainbowKit UIs
*/
iconUrl: string;
/**
* Will show up as the wallet's image background in RainbowKit UIs.
*
* @default '#000000'
*/
iconBackground?: string;
}
/**
* Create a RainbowKit wallet for a Privy cross-app waller
*
* @example
* import { connectorsForWallets } from "@rainbow-me/rainbowkit";
*
* const privyWallet = toPrivyWallet({
* id: <privy-wallet-app-id>,
* name: 'Privy wallet app',
* iconUrl: 'https://example.com/image.png',
* })
*
* const connectors = connectorsForWallets(
* [
* {
* groupName: "Privy",
* wallets: [privyWallet],
* },
* ],
* {
* appName: "Privy",
* projectId: "Example",
* }
* );
*/
declare const toPrivyWallet: (opts: CreatePrivyWalletOptions) => () => Wallet;
export { type CreatePrivyConnectorOptions, type CreatePrivyWalletOptions, toPrivyWallet, toPrivyWalletConnector };