22 * @prettier
33 */
44import * as secp256k1 from 'secp256k1' ;
5- import { randomBytes } from 'crypto' ;
5+ import { createHash , Hash , randomBytes } from 'crypto' ;
66import { CoinFamily , BaseCoin as StaticsBaseCoin } from '@bitgo/statics' ;
77import { bip32 } from '@bitgo/secp256k1' ;
88import * as request from 'superagent' ;
@@ -16,6 +16,7 @@ import {
1616 KeyPair ,
1717 KeyIndices ,
1818 MethodNotImplementedError ,
19+ MPCAlgorithm ,
1920 ParsedTransaction ,
2021 ParseTransactionOptions ,
2122 SignedTransaction ,
@@ -31,7 +32,10 @@ import {
3132 multisigTypes ,
3233 AuditDecryptedKeyParams ,
3334 AddressCoinSpecific ,
35+ verifyMPCWalletAddress ,
36+ isTssVerifyAddressOptions ,
3437} from '@bitgo/sdk-core' ;
38+ import { auditEcdsaPrivateKey } from '@bitgo/sdk-lib-mpc' ;
3539import { Interface , Utils , WrappedBuilder , KeyPair as TronKeyPair } from './lib' ;
3640import { ValueFields , TransactionReceipt } from './lib/iface' ;
3741import { getBuilder } from './lib/builder' ;
@@ -189,6 +193,21 @@ export class Trx extends BaseCoin {
189193 return multisigTypes . onchain ;
190194 }
191195
196+ /** @inheritDoc */
197+ supportsTss ( ) : boolean {
198+ return true ;
199+ }
200+
201+ /** @inheritDoc */
202+ getMPCAlgorithm ( ) : MPCAlgorithm {
203+ return 'ecdsa' ;
204+ }
205+
206+ /** @inheritDoc */
207+ getHashFunction ( ) : Hash {
208+ return createHash ( 'sha256' ) ;
209+ }
210+
192211 static createInstance ( bitgo : BitGoBase , staticsCoin ?: Readonly < StaticsBaseCoin > ) : BaseCoin {
193212 return new Trx ( bitgo , staticsCoin ) ;
194213 }
@@ -269,6 +288,14 @@ export class Trx extends BaseCoin {
269288 async isWalletAddress ( params : VerifyAddressOptions ) : Promise < boolean > {
270289 const { address, keychains } = params ;
271290
291+ if ( isTssVerifyAddressOptions ( params ) ) {
292+ return verifyMPCWalletAddress (
293+ { ...params , keyCurve : 'secp256k1' } ,
294+ this . isValidAddress . bind ( this ) ,
295+ ( pubKey : string ) => new TronKeyPair ( { pub : pubKey } ) . getAddress ( )
296+ ) ;
297+ }
298+
272299 if ( ! isTrxVerifyAddressOptions ( params ) ) {
273300 throw new Error ( 'Invalid or missing index for address verification' ) ;
274301 }
@@ -404,6 +431,13 @@ export class Trx extends BaseCoin {
404431 return true ;
405432 }
406433
434+ /** @inheritDoc */
435+ async getSignablePayload ( serializedTx : string ) : Promise < Buffer > {
436+ const txBuilder = getBuilder ( this . getChain ( ) ) . from ( serializedTx ) ;
437+ const rebuiltTransaction = await txBuilder . build ( ) ;
438+ return rebuiltTransaction . signablePayload ;
439+ }
440+
407441 /**
408442 * Derive a user key using the chain path of the address
409443 * @param key
@@ -1071,7 +1105,11 @@ export class Trx extends BaseCoin {
10711105 }
10721106
10731107 /** @inheritDoc */
1074- auditDecryptedKey ( params : AuditDecryptedKeyParams ) {
1075- throw new MethodNotImplementedError ( ) ;
1108+ auditDecryptedKey ( { multiSigType, publicKey, prv } : AuditDecryptedKeyParams ) {
1109+ if ( multiSigType === 'tss' ) {
1110+ auditEcdsaPrivateKey ( prv as string , publicKey as string ) ;
1111+ } else {
1112+ throw new MethodNotImplementedError ( ) ;
1113+ }
10761114 }
10771115}
0 commit comments