near-ca
Version:
An SDK for controlling Ethereum Accounts from a Near Account.
107 lines (106 loc) • 3.75 kB
TypeScript
import { Contract, Account } from "near-api-js";
import { Address, Signature } from "viem";
import { MPCSignature, FunctionCallTransaction, SignArgs } from "./types";
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
/**
* Near Contract Type for change methods.
*
* @typeParam T - The type of the arguments for the change method
*/
export interface ChangeMethodArgs<T> {
/** Change method function arguments */
args: T;
/** Gas limit on transaction execution */
gas: string;
/** Account signing the call */
signerAccount: Account;
/** Attached deposit (i.e., payable amount) to attach to the transaction */
amount: string;
}
/** Interface extending the base NEAR Contract with MPC-specific methods */
interface MpcContractInterface extends Contract {
/** Returns the public key */
public_key: () => Promise<string>;
/** Returns required deposit based on current request queue */
experimental_signature_deposit: () => Promise<number>;
/** Signs a request using the MPC contract */
sign: (args: ChangeMethodArgs<{
request: SignArgs;
}>) => Promise<MPCSignature>;
}
/**
* High-level interface for the Near MPC-Recovery Contract
* located in: https://github.com/near/mpc-recovery
*/
export declare class MpcContract implements IMpcContract {
rootPublicKey: string | undefined;
contract: MpcContractInterface;
connectedAccount: Account;
/**
* Creates a new MPC Contract instance
*
* @param account - The NEAR account to use
* @param contractId - The contract ID
* @param rootPublicKey - Optional root public key
*/
constructor(account: Account, contractId: string, rootPublicKey?: string);
/**
* Gets the contract ID
*
* @returns The contract ID
*/
accountId(): string;
/**
* Derives an Ethereum address from a derivation path
*
* @param derivationPath - The path to derive the address from
* @returns The derived Ethereum address
*/
deriveEthAddress: (derivationPath: string) => Promise<Address>;
/**
* Gets the required deposit for the signature
*
* @returns The required deposit amount as a string
*/
getDeposit: () => Promise<string>;
/**
* Requests a signature from the MPC contract
*
* @param signArgs - The arguments for the signature request
* @param gas - Optional gas limit
* @returns The signature
*/
requestSignature: (signArgs: SignArgs, gas?: bigint) => Promise<Signature>;
/**
* Encodes a signature request into a transaction
*
* @param signArgs - The arguments for the signature request
* @param gas - Optional gas limit
* @returns The encoded transaction
*/
encodeSignatureRequestTx(signArgs: SignArgs, gas?: bigint): Promise<FunctionCallTransaction<{
request: SignArgs;
}>>;
/**
* Signs and sends a signature request
*
* @param transaction - The transaction to sign and send
* @param blockTimeout - Optional timeout in blocks
* @returns The execution outcome
*/
signAndSendSignRequest(transaction: FunctionCallTransaction<{
request: SignArgs;
}>, blockTimeout?: number): Promise<FinalExecutionOutcome>;
}
/** Interface for MPC Contract implementation */
export interface IMpcContract {
connectedAccount: Account;
accountId(): string;
deriveEthAddress(derivationPath: string): Promise<Address>;
getDeposit(): Promise<string>;
requestSignature(signArgs: SignArgs, gas?: bigint): Promise<Signature>;
encodeSignatureRequestTx(signArgs: SignArgs, gas?: bigint): Promise<FunctionCallTransaction<{
request: SignArgs;
}>>;
}
export {};