File tree Expand file tree Collapse file tree
modules/sdk-core/src/coins Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
1515 SignTransactionOptions ,
1616 VerifyAddressOptions ,
1717 VerifyTransactionOptions ,
18+ Wallet ,
1819} from '../' ;
1920
2021export class Ofc extends BaseCoin {
@@ -104,6 +105,26 @@ export class Ofc extends BaseCoin {
104105 throw new MethodNotImplementedError ( ) ;
105106 }
106107
108+ /**
109+ * Signs a message using a trading wallet's BitGo Key
110+ * @param wallet - uses the BitGo key of this trading wallet to sign the message remotely in a KMS
111+ * @param message
112+ */
113+ async signMessage ( wallet : Wallet , message : string ) : Promise < Buffer > ;
114+ /**
115+ * Signs a message using the private key
116+ * @param key - uses the private key to sign the message
117+ * @param message
118+ */
119+ async signMessage ( key : { prv : string } , message : string ) : Promise < Buffer > ;
120+ async signMessage ( keyOrWallet : { prv : string } | Wallet , message : string ) : Promise < Buffer > {
121+ if ( ! ( keyOrWallet instanceof Wallet ) ) {
122+ return super . signMessage ( keyOrWallet as { prv : string } , message ) ;
123+ }
124+ const signatureHexString = await ( keyOrWallet as Wallet ) . toTradingAccount ( ) . signPayload ( { payload : message } ) ;
125+ return Buffer . from ( signatureHexString , 'hex' ) ;
126+ }
127+
107128 /** @inheritDoc */
108129 auditDecryptedKey ( params : AuditDecryptedKeyParams ) {
109130 throw new MethodNotImplementedError ( ) ;
Original file line number Diff line number Diff line change 99 SignTransactionOptions as BaseSignTransactionOptions ,
1010 SignedTransaction ,
1111 ITransactionRecipient ,
12+ Wallet ,
1213} from '../' ;
1314import { isBolt11Invoice } from '../lightning' ;
1415
@@ -18,7 +19,8 @@ export interface SignTransactionOptions extends BaseSignTransactionOptions {
1819 txPrebuild : {
1920 payload : string ;
2021 } ;
21- prv : string ;
22+ prv ?: string ;
23+ wallet ?: Wallet ;
2224}
2325
2426export { OfcTokenConfig } ;
@@ -107,15 +109,25 @@ export class OfcToken extends Ofc {
107109 }
108110
109111 /**
110- * Assemble keychain and half-sign prebuilt transaction
112+ * Signs a half-signed OFC transaction.
113+ * Signs the transaction remotely using the BitGo key if prv is not provided.
111114 * @param params
112115 * @returns {Promise<SignedTransaction> }
113116 */
114117 async signTransaction ( params : SignTransactionOptions ) : Promise < SignedTransaction > {
115118 const txPrebuild = params . txPrebuild ;
116119 const payload = txPrebuild . payload ;
117- const signatureBuffer = ( await this . signMessage ( params , payload ) ) as any ;
118- const signature : string = signatureBuffer . toString ( 'hex' ) ;
120+
121+ let signature : string ;
122+ if ( params . wallet ) {
123+ signature = await params . wallet . toTradingAccount ( ) . signPayload ( { payload, walletPassphrase : params . prv } ) ;
124+ } else if ( params . prv ) {
125+ const signatureBuffer = ( await this . signMessage ( { prv : params . prv } , payload ) ) as any ;
126+ signature = signatureBuffer . toString ( 'hex' ) ;
127+ } else {
128+ throw new Error ( 'You must pass in either one of wallet or prv' ) ;
129+ }
130+
119131 return { halfSigned : { payload, signature } } as any ;
120132 }
121133
You can’t perform that action at this time.
0 commit comments