@@ -267,29 +267,39 @@ export class LumClient {
267267 /**
268268 * Signs the messages using the provided wallet and builds the transaction
269269 *
270- * @param wallets signing wallets for multi signature
270+ * @param wallet signing wallet for multi signature
271271 * @param doc document to sign
272272 */
273- signTx = async < T > ( wallets : T , doc : LumTypes . Doc ) : Promise < Uint8Array > => {
274- let signDoc : LumTypes . SignDoc | undefined = undefined ;
273+ signTx = async ( wallet : LumWallet , doc : LumTypes . Doc ) : Promise < Uint8Array > => {
275274 const signatures : Uint8Array [ ] = [ ] ;
275+ const [ signedDoc , signature ] = await this . signTxFromWallet ( wallet , doc ) ;
276276
277- if ( wallets instanceof LumWallet ) {
278- const [ walletSignedDoc , signature ] = await this . signTxFromWallet ( wallets , doc ) ;
277+ signatures . push ( signature ) ;
279278
280- signatures . push ( signature ) ;
281- signDoc = walletSignedDoc ;
279+ if ( ! signedDoc || signatures . length === 0 ) {
280+ throw new Error ( 'Failed to sign the document: no signature provided' ) ;
282281 }
283282
284- if ( wallets instanceof Array ) {
285- for ( const wallet of wallets ) {
286- const [ walletSignedDoc , signature ] = await this . signTxFromWallet ( wallet , doc ) ;
283+ return LumUtils . generateTxBytes ( signedDoc , signatures ) ;
284+ } ;
287285
288- signatures . push ( signature ) ;
286+ /**
287+ * Signs the messages using the provided wallets and builds the transaction
288+ *
289+ * @param wallets signing wallets for multi signature
290+ * @param doc document to sign
291+ */
292+ signTxForMultiWallet = async ( wallets : LumWallet [ ] , doc : LumTypes . Doc ) : Promise < Uint8Array > => {
293+ let signDoc : LumTypes . SignDoc | undefined = undefined ;
294+ const signatures : Uint8Array [ ] = [ ] ;
289295
290- if ( ! signDoc ) {
291- signDoc = walletSignedDoc ;
292- }
296+ for ( const wallet of wallets ) {
297+ const [ walletSignedDoc , signature ] = await this . signTxFromWallet ( wallet , doc ) ;
298+
299+ signatures . push ( signature ) ;
300+
301+ if ( ! signDoc ) {
302+ signDoc = walletSignedDoc ;
293303 }
294304 }
295305
@@ -326,8 +336,15 @@ export class LumClient {
326336 * @param wallet signing wallet or wallets for multi signature
327337 * @param doc document to sign and broadcast as a transaction
328338 */
329- signAndBroadcastTx = async ( wallet : LumWallet | LumWallet [ ] , doc : LumTypes . Doc ) : Promise < LumTypes . BroadcastTxCommitResponse > => {
339+ signAndBroadcastTx = async ( wallet : LumWallet , doc : LumTypes . Doc ) : Promise < LumTypes . BroadcastTxCommitResponse > => {
330340 const signedTx = await this . signTx ( wallet , doc ) ;
341+
342+ return this . broadcastTx ( signedTx ) ;
343+ } ;
344+
345+ signAndBroadcastTxForMultiWallet = async ( wallets : LumWallet [ ] , doc : LumTypes . Doc ) : Promise < LumTypes . BroadcastTxCommitResponse > => {
346+ const signedTx = await this . signTxForMultiWallet ( wallets , doc ) ;
347+
331348 return this . broadcastTx ( signedTx ) ;
332349 } ;
333350}
0 commit comments