@@ -24,6 +24,8 @@ export abstract class Transaction<T> extends BaseTransaction {
2424 protected _suiTransaction : SuiTransaction < T > ;
2525 protected _signature : Signature ;
2626 private _serializedSig : Uint8Array ;
27+ protected _feePayerSignature : Signature ;
28+ private _serializedFeePayerSig : Uint8Array ;
2729
2830 protected constructor ( _coinConfig : Readonly < CoinConfig > ) {
2931 super ( _coinConfig ) ;
@@ -51,6 +53,12 @@ export abstract class Transaction<T> extends BaseTransaction {
5153 this . serialize ( ) ;
5254 }
5355
56+ addFeePayerSignature ( publicKey : BasePublicKey , signature : Buffer ) : void {
57+ this . _signatures . push ( signature . toString ( 'hex' ) ) ;
58+ this . _feePayerSignature = { publicKey, signature } ;
59+ this . serialize ( ) ;
60+ }
61+
5462 get suiSignature ( ) : Signature {
5563 return this . _signature ;
5664 }
@@ -59,6 +67,10 @@ export abstract class Transaction<T> extends BaseTransaction {
5967 return this . _serializedSig ;
6068 }
6169
70+ get serializedFeePayerSig ( ) : Uint8Array {
71+ return this . _serializedFeePayerSig ;
72+ }
73+
6274 setSerializedSig ( publicKey : BasePublicKey , signature : Buffer ) : void {
6375 const pubKey = Buffer . from ( publicKey . pub , 'hex' ) ;
6476 const serialized_sig = new Uint8Array ( 1 + signature . length + pubKey . length ) ;
@@ -68,6 +80,15 @@ export abstract class Transaction<T> extends BaseTransaction {
6880 this . _serializedSig = serialized_sig ;
6981 }
7082
83+ setSerializedFeePayerSig ( publicKey : BasePublicKey , signature : Buffer ) : void {
84+ const pubKey = Buffer . from ( publicKey . pub , 'hex' ) ;
85+ const serialized_sig = new Uint8Array ( 1 + signature . length + pubKey . length ) ;
86+ serialized_sig . set ( SIGNATURE_SCHEME_BYTES ) ;
87+ serialized_sig . set ( signature , 1 ) ;
88+ serialized_sig . set ( pubKey , 1 + signature . length ) ;
89+ this . _serializedFeePayerSig = serialized_sig ;
90+ }
91+
7192 /** @inheritdoc */
7293 canSign ( key : BaseKey ) : boolean {
7394 return true ;
@@ -91,6 +112,28 @@ export abstract class Transaction<T> extends BaseTransaction {
91112 this . addSignature ( { pub : signer . getKeys ( ) . pub } , Buffer . from ( signature ) ) ;
92113 }
93114
115+ /**
116+ * Sign transaction as the gas owner (fee payer).
117+ *
118+ * @param {KeyPair } ownerKey - Key for gas owner.
119+ */
120+ signAsFeePayer ( signer : KeyPair ) : void {
121+ if ( ! this . _suiTransaction ) {
122+ throw new InvalidTransactionError ( 'empty transaction to sign' ) ;
123+ }
124+
125+ const intentMessage = this . signablePayload ;
126+ const signature = signer . signMessageinUint8Array ( intentMessage ) ;
127+
128+ this . _feePayerSignature = {
129+ publicKey : { pub : signer . getKeys ( ) . pub } ,
130+ signature : Buffer . from ( signature ) ,
131+ } ;
132+
133+ // Set serialized signature for fee payer
134+ this . setSerializedFeePayerSig ( { pub : signer . getKeys ( ) . pub } , Buffer . from ( signature ) ) ;
135+ }
136+
94137 /** @inheritdoc */
95138 toBroadcastFormat ( ) : string {
96139 if ( ! this . _suiTransaction ) {
0 commit comments