UNPKG

near-ca

Version:

An SDK for controlling Ethereum Accounts from a Near Account.

112 lines (111 loc) 4.84 kB
import { Address, Hex, Hash, SignableMessage, TypedData, TypedDataDefinition } from "viem"; import { BaseTx, AdapterParams, FunctionCallTransaction, TxPayload, SignArgs, SignRequestData, IMpcContract, NearEncodedSignRequest } from ".."; import { Beta } from "../beta"; /** * Adapter class for interacting with Ethereum through NEAR MPC contract */ export declare class NearEthAdapter { readonly mpcContract: IMpcContract; readonly address: Address; readonly derivationPath: string; readonly beta: Beta; private constructor(); /** * Gets the NEAR account ID linked to derived EVM account * * @returns The connected NEAR account ID */ nearAccountId(): string; /** * Retrieves the balance of the Ethereum address associated with this adapter * * @param chainId - The chain ID of the Ethereum network to query * @returns The balance of the address in wei */ getBalance(chainId: number): Promise<bigint>; /** * Constructs an EVM instance with the provided configuration * * @param args - The configuration object for the Adapter instance * @returns A new NearEthAdapter instance */ static fromConfig(args: AdapterParams): Promise<NearEthAdapter>; /** * Takes a minimally declared Ethereum Transaction, * builds the full transaction payload (with gas estimates, prices etc...), * acquires signature from Near MPC Contract and submits transaction to public mempool * * @param txData - Minimal transaction data to be signed by Near MPC and executed on EVM * @param nearGas - Manually specified gas to be sent with signature request * @returns The ethereum transaction hash */ signAndSendTransaction(txData: BaseTx, nearGas?: bigint): Promise<Hash>; /** * Takes a minimally declared Ethereum Transaction, * builds the full transaction payload (with gas estimates, prices etc...), * and prepares the signature request payload for the Near MPC Contract * * @param txData - Minimal transaction data to be signed by Near MPC and executed on EVM * @param nearGas - Manually specified gas to be sent with signature request * @returns The transaction and request payload */ getSignatureRequestPayload(txData: BaseTx, nearGas?: bigint): Promise<{ transaction: Hex; requestPayload: FunctionCallTransaction<{ request: SignArgs; }>; }>; /** * Builds a Near Transaction Payload for Signing serialized EVM Transaction * * @param transaction - RLP encoded (i.e. serialized) Ethereum Transaction * @param nearGas - Optional gas parameter * @returns Prepared Near Transaction with signerId as this.address */ mpcSignRequest(transaction: Hex, nearGas?: bigint): Promise<FunctionCallTransaction<{ request: SignArgs; }>>; /** * Builds a complete, unsigned transaction (with nonce, gas estimates, current prices) * and payload bytes in preparation to be relayed to Near MPC contract * * @param tx - Minimal transaction data to be signed by Near MPC and executed on EVM * @returns Transaction and its bytes (the payload to be signed on Near) */ createTxPayload(tx: BaseTx): Promise<TxPayload>; /** * Transforms minimal transaction request data into a fully populated EVM transaction * * @param tx - Minimal transaction request data * @returns Serialized (aka RLP encoded) transaction */ buildTransaction(tx: BaseTx): Promise<Hex>; /** * Signs typed data according to EIP-712 * * @param typedData - The typed data to sign * @returns The signature hash */ signTypedData<const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(typedData: TypedDataDefinition<typedData, primaryType>): Promise<Hash>; /** * Signs a message according to personal_sign * * @param message - The message to sign * @returns The signature hash */ signMessage(message: SignableMessage): Promise<Hash>; /** * Requests signature from Near MPC Contract * * @param msgHash - Message Hash to be signed * @returns Two different potential signatures for the hash (one of which is valid) */ sign(msgHash: `0x${string}` | Uint8Array): Promise<Hex>; /** * Encodes a signature request for submission to the Near-Ethereum transaction MPC contract * * @param signRequest - The signature request data containing method, chain ID, and parameters * @returns The encoded Near-Ethereum transaction data, original EVM message, and recovery data */ encodeSignRequest(signRequest: SignRequestData): Promise<NearEncodedSignRequest>; }