UNPKG

near-ca-test

Version:

An SDK for controlling Ethereum Accounts from a Near Account.

100 lines (99 loc) 5.08 kB
import { Address, Hex, Hash, SignableMessage, TypedData, TypedDataDefinition } from "viem"; import { BaseTx, AdapterParams, FunctionCallTransaction, TxPayload, SignArgs, SignRequestData, IMpcContract, NearEncodedSignRequest } from ".."; import { Beta } from "../beta"; export declare class NearEthAdapter { readonly mpcContract: IMpcContract; readonly address: Address; readonly derivationPath: string; readonly beta: Beta; private constructor(); /** * @returns Near accountId linked to derived ETH. */ nearAccountId(): string; /** * Retrieves the balance of the Ethereum address associated with this adapter. * * @param {number} chainId - The chain ID of the Ethereum network to query. * @returns {Promise<bigint>} - A promise that resolves to the balance of the address in wei. */ getBalance(chainId: number): Promise<bigint>; /** * Constructs an EVM instance with the provided configuration. * @param {AdapterParams} args - The configuration object for the Adapter instance. */ static fromConfig(args: AdapterParams): Promise<NearEthAdapter>; /** * Constructs an EVM instance with the provided configuration. * @param {AdapterParams} args - The configuration object for the Adapter instance. */ static mocked(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 {BaseTx} txData - Minimal transaction data to be signed by Near MPC and executed on EVM. * @param {bigint} nearGas - manually specified gas to be sent with signature request. * Note that the signature request is a recursive function. */ signAndSendTransaction(txData: BaseTx, nearGas?: bigint): Promise<Hash>; /** * 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 {BaseTx} txData - Minimal transaction data to be signed by Near MPC and executed on EVM. * @param {bigint} nearGas - manually specified gas to be sent with signature request. * Note that the signature request is a recursive function. */ getSignatureRequestPayload(txData: BaseTx, nearGas?: bigint): Promise<{ transaction: Hex; requestPayload: FunctionCallTransaction<{ request: SignArgs; }>; }>; /** * Builds a Near Transaction Payload for Signing serialized EVM Transaction. * @param {Hex} transaction RLP encoded (i.e. serialized) Ethereum Transaction * @param nearGas optional gas parameter * @returns {FunctionCallTransaction<SignArgs>} 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 {BaseTx} tx - Minimal transaction data to be signed by Near MPC and executed on EVM. * @param {number?} nonce - Optional transaction nonce. * @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 {BaseTx} tx - Minimal transaction request data * @returns {Hex} serialized (aka RLP encoded) transaction. */ buildTransaction(tx: BaseTx): Promise<Hex>; signTypedData<const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(typedData: TypedDataDefinition<typedData, primaryType>): Promise<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. * * @async * @function encodeSignRequest * @param {SignRequestData} signRequest - The signature request data containing method, chain ID, and parameters. * @returns {Promise<NearEthTxData>} * - Returns a promise that resolves to an object containing the encoded Near-Ethereum transaction data, * the original EVM message, and recovery data necessary for verifying or reconstructing the signature. */ encodeSignRequest(signRequest: SignRequestData): Promise<NearEncodedSignRequest>; }