@@ -267,29 +267,39 @@ export class LumClient {
267
267
/**
268
268
* Signs the messages using the provided wallet and builds the transaction
269
269
*
270
- * @param wallets signing wallets for multi signature
270
+ * @param wallet signing wallet for multi signature
271
271
* @param doc document to sign
272
272
*/
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 > => {
275
274
const signatures : Uint8Array [ ] = [ ] ;
275
+ const [ signedDoc , signature ] = await this . signTxFromWallet ( wallet , doc ) ;
276
276
277
- if ( wallets instanceof LumWallet ) {
278
- const [ walletSignedDoc , signature ] = await this . signTxFromWallet ( wallets , doc ) ;
277
+ signatures . push ( signature ) ;
279
278
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' ) ;
282
281
}
283
282
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
+ } ;
287
285
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 [ ] = [ ] ;
289
295
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 ;
293
303
}
294
304
}
295
305
@@ -326,8 +336,15 @@ export class LumClient {
326
336
* @param wallet signing wallet or wallets for multi signature
327
337
* @param doc document to sign and broadcast as a transaction
328
338
*/
329
- signAndBroadcastTx = async ( wallet : LumWallet | LumWallet [ ] , doc : LumTypes . Doc ) : Promise < LumTypes . BroadcastTxCommitResponse > => {
339
+ signAndBroadcastTx = async ( wallet : LumWallet , doc : LumTypes . Doc ) : Promise < LumTypes . BroadcastTxCommitResponse > => {
330
340
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
+
331
348
return this . broadcastTx ( signedTx ) ;
332
349
} ;
333
350
}
0 commit comments