@oasisprotocol/sapphire-viem-v2
Version:
Viem support for the Oasis Sapphire ParaTime.
115 lines • 3.91 kB
TypeScript
import { type SapphireWrapConfig } from "@oasisprotocol/sapphire-paratime";
import type { Client, HttpTransportConfig, SerializeTransactionFn, Transport, WalletClient } from "viem";
/**
* sapphire-localnet chain, a local chain for local people
*/
export declare const sapphireLocalnet: {
blockExplorers?: {
[key: string]: {
name: string;
url: string;
apiUrl?: string | undefined;
};
default: {
name: string;
url: string;
apiUrl?: string | undefined;
};
} | undefined | undefined;
contracts?: {
[x: string]: import("viem").ChainContract | {
[sourceId: number]: import("viem").ChainContract | undefined;
} | undefined;
ensRegistry?: import("viem").ChainContract | undefined;
ensUniversalResolver?: import("viem").ChainContract | undefined;
multicall3?: import("viem").ChainContract | undefined;
} | undefined;
id: number;
name: "Oasis Sapphire Localnet";
nativeCurrency: {
readonly name: "Sapphire Local Rose";
readonly symbol: "TEST";
readonly decimals: 18;
};
rpcUrls: {
readonly default: {
readonly http: readonly [string];
};
};
sourceId?: number | undefined | undefined;
testnet: true;
custom?: Record<string, unknown> | undefined;
formatters?: undefined;
serializers?: import("viem").ChainSerializers<undefined> | undefined;
fees?: import("viem").ChainFees<undefined> | undefined;
readonly network: "sapphire-localnet";
};
export declare const SAPPHIRE_WRAPPED_VIEM_TRANSPORT: unique symbol;
type EthereumProvider = {
request(...args: unknown[]): Promise<any>;
};
export type SapphireHttpTransport = Transport<"sapphire", {}, EthereumProvider["request"]>;
/**
* Provide a Sapphire encrypted RPC transport for Wagmi or Viem.
*
* Example:
* ```
* import { createConfig } from 'viem';
* import { sapphireHttpTransport } from '@oasisprotocol/sapphire-viem-v2';
*
* export const config = createConfig({
* transports: {
* [sapphireTestnet.id]: sapphireHttpTransport()
* },
* ...
* });
* ```
*
* Results for every instance of sapphireHttpTransport() are cached to prevent
* the wrapper from being instantiated multiple times.
*
* @returns Same as http()
*/
export declare function sapphireHttpTransport<T extends Transport>(sapphireConfig?: SapphireWrapConfig, overrideUrl?: string, httpConfig?: HttpTransportConfig): T;
/**
* Creates a Viem transaction serializer which encrypts transactions prior to
* them being signed. This is compatible with both local wallet clients and
* injected wallets.
*
* Example
* ```
* import { defineChain } from 'viem';
* import { createSapphireSerializer } from '@oasisprotocol/sapphire-viem-v2';
*
* defineChain({
* serializers: {
* transaction: createSapphireSerializer(publicClient)
* },
* ...
* });
* ```
*
* @param client Provides upstream access to Sapphire JSON-RPC via `.request`
* @param originalSerializer Optional serializer to wrap, otherwise will use default
* @returns Sapphire wrapped transaction encryption serializer
*/
export declare function createSapphireSerializer<C extends Client, S extends SerializeTransactionFn>(client: C, originalSerializer?: S | undefined): Promise<S>;
export declare const SAPPHIRE_WRAPPED_VIEM_SERIALIZER: unique symbol;
/**
* Add the Sapphire transaction encryption wrapper to a wallet client
*
* Example:
* ```
* walletClient = await wrapWalletClient(createWalletClient({
* account,
* chain: sapphireLocalnet,
* transport: sapphireHttpTransport()
* }));
* ```
*
* @param client Wagmi wallet client
* @returns wrapped wallet client
*/
export declare function wrapWalletClient<T extends WalletClient>(client: T): Promise<T>;
export {};
//# sourceMappingURL=index.d.ts.map