1- import { Contract , Account , transactions } from "near-api-js" ;
1+ import { Account , transactions } from "near-api-js" ;
22import { Address , Signature } from "viem" ;
33import {
44 deriveChildPublicKey ,
77 uncompressedHexPointToEvmAddress ,
88} from "./utils" ;
99import { TGAS } from "./chains" ;
10- import { MPCSignature , FunctionCallTransaction , SignArgs } from "./types" ;
10+ import { FunctionCallTransaction , SignArgs } from "./types" ;
1111import { FinalExecutionOutcome } from "near-api-js/lib/providers" ;
1212
1313/**
@@ -26,25 +26,14 @@ export interface ChangeMethodArgs<T> {
2626 amount : string ;
2727}
2828
29- /** Interface extending the base NEAR Contract with MPC-specific methods */
30- interface MpcContractInterface extends Contract {
31- /** Returns the public key */
32- public_key : ( ) => Promise < string > ;
33- /** Returns required deposit based on current request queue */
34- experimental_signature_deposit : ( ) => Promise < number > ;
35- /** Signs a request using the MPC contract */
36- sign : (
37- args : ChangeMethodArgs < { request : SignArgs } >
38- ) => Promise < MPCSignature > ;
39- }
40-
4129/**
4230 * High-level interface for the Near MPC-Recovery Contract
4331 * located in: https://github.com/near/mpc-recovery
4432 */
4533export class MpcContract implements IMpcContract {
4634 rootPublicKey : string | undefined ;
47- contract : MpcContractInterface ;
35+ contractId : string ;
36+ // contract: MpcContractInterface;
4837 connectedAccount : Account ;
4938
5039 /**
@@ -57,12 +46,7 @@ export class MpcContract implements IMpcContract {
5746 constructor ( account : Account , contractId : string , rootPublicKey ?: string ) {
5847 this . connectedAccount = account ;
5948 this . rootPublicKey = rootPublicKey ;
60-
61- this . contract = new Contract ( account . getConnection ( ) , contractId , {
62- changeMethods : [ "sign" ] ,
63- viewMethods : [ "public_key" , "experimental_signature_deposit" ] ,
64- useLocalViewExecution : false ,
65- } ) as MpcContractInterface ;
49+ this . contractId = contractId ;
6650 }
6751
6852 /**
@@ -71,7 +55,7 @@ export class MpcContract implements IMpcContract {
7155 * @returns The contract ID
7256 */
7357 accountId ( ) : string {
74- return this . contract . contractId ;
58+ return this . contractId ;
7559 }
7660
7761 /**
@@ -82,36 +66,22 @@ export class MpcContract implements IMpcContract {
8266 */
8367 deriveEthAddress = async ( derivationPath : string ) : Promise < Address > => {
8468 if ( ! this . rootPublicKey ) {
85- this . rootPublicKey = await this . contract . public_key ( ) ;
69+ this . rootPublicKey = await this . connectedAccount . provider . callFunction (
70+ this . contractId ,
71+ "public_key" ,
72+ { }
73+ ) ;
8674 }
8775
8876 const publicKey = deriveChildPublicKey (
89- najPublicKeyStrToUncompressedHexPoint ( this . rootPublicKey ) ,
77+ najPublicKeyStrToUncompressedHexPoint ( this . rootPublicKey ! ) ,
9078 this . connectedAccount . accountId ,
9179 derivationPath
9280 ) ;
9381
9482 return uncompressedHexPointToEvmAddress ( publicKey ) ;
9583 } ;
9684
97- /**
98- * Gets the required deposit for the signature
99- *
100- * @returns The required deposit amount as a string
101- */
102- getDeposit = async ( ) : Promise < string > => {
103- try {
104- const deposit = await this . contract . experimental_signature_deposit ( ) ;
105- return BigInt (
106- deposit . toLocaleString ( "fullwide" , { useGrouping : false } )
107- ) . toString ( ) ;
108- } catch {
109- // They are phasing out experimental_signature_deposit.
110- // required deposit is 1 yocto (see v1.signer-prod.testnet).
111- return "1" ;
112- }
113- } ;
114-
11585 /**
11686 * Requests a signature from the MPC contract
11787 *
@@ -141,15 +111,15 @@ export class MpcContract implements IMpcContract {
141111 ) : Promise < FunctionCallTransaction < { request : SignArgs } > > {
142112 return {
143113 signerId : this . connectedAccount . accountId ,
144- receiverId : this . contract . contractId ,
114+ receiverId : this . contractId ,
145115 actions : [
146116 {
147117 type : "FunctionCall" ,
148118 params : {
149119 methodName : "sign" ,
150120 args : { request : signArgs } ,
151121 gas : gasOrDefault ( gas ) ,
152- deposit : await this . getDeposit ( ) ,
122+ deposit : "1" ,
153123 } ,
154124 } ,
155125 ] ,
@@ -168,7 +138,7 @@ export class MpcContract implements IMpcContract {
168138 ) : Promise < FinalExecutionOutcome > {
169139 const account = this . connectedAccount ;
170140 const signedTx = await account . createSignedTransaction (
171- this . contract . contractId ,
141+ this . contractId ,
172142 transaction . actions . map ( ( { params : { args, gas, deposit } } ) =>
173143 transactions . functionCall ( "sign" , args , BigInt ( gas ) , BigInt ( deposit ) )
174144 )
@@ -195,7 +165,6 @@ export interface IMpcContract {
195165 connectedAccount : Account ;
196166 accountId ( ) : string ;
197167 deriveEthAddress ( derivationPath : string ) : Promise < Address > ;
198- getDeposit ( ) : Promise < string > ;
199168 requestSignature ( signArgs : SignArgs , gas ?: bigint ) : Promise < Signature > ;
200169 encodeSignatureRequestTx (
201170 signArgs : SignArgs ,
0 commit comments