near-safe
Version:
An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.
43 lines (42 loc) • 2.45 kB
TypeScript
import { SessionRequestParams } from "near-ca";
import { Address, Hex, PublicClient } from "viem";
import { PaymasterData, MetaTransaction, UserOperation } from "./types";
export declare const PLACEHOLDER_SIG: `0x${string}`;
type IntLike = Hex | bigint | string | number;
export declare const packGas: (hi: IntLike, lo: IntLike) => string;
export declare function packSignature(signature: `0x${string}`, validFrom?: number, validTo?: number): Hex;
export declare function packPaymasterData(data: PaymasterData): Hex;
export declare function containsValue(transactions: MetaTransaction[]): boolean;
export declare function isContract(address: Address, chainId: number): Promise<boolean>;
export declare function getClient(chainId: number, rpcUrl?: string): PublicClient;
export declare function metaTransactionsFromRequest(params: SessionRequestParams): MetaTransaction[];
export declare function saltNonceFromMessage(input: string): string;
/**
* Fetches the signature for a NEAR transaction hash. If an `accountId` is provided,
* it fetches the signature from the appropriate network. Otherwise, it races across
* both `testnet` and `mainnet`.
*
* @param {string} txHash - The NEAR transaction hash for which to fetch the signature.
* @param {string} [accountId] - (Optional) The account ID associated with the transaction.
* Providing this will reduce dangling promises as the network is determined by the account.
*
* @returns {Promise<Hex>} A promise that resolves to the hex-encoded signature.
*
* @throws Will throw an error if no signature is found for the given transaction hash.
*/
export declare function signatureFromTxHash(txHash: string, accountId?: string): Promise<Hex>;
/**
* Races an array of promises and resolves with the first promise that fulfills.
* If all promises reject, the function will reject with an error.
*
* @template T
* @param {Promise<T>[]} promises - An array of promises to race. Each promise should resolve to type `T`.
*
* @returns {Promise<T>} A promise that resolves to the value of the first successfully resolved promise.
*
* @throws Will throw an error if all promises reject with the message "All promises rejected".
*/
export declare function raceToFirstResolve<T>(promises: Promise<T>[]): Promise<T>;
export declare function assertUnique<T>(iterable: Iterable<T>, errorMessage?: string): void;
export declare function userOpTransactionCost(userOp: UserOperation): bigint;
export {};