diff --git a/package.json b/package.json index 8499871..126127b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kilnfi/sdk", - "version": "4.2.26", + "version": "4.2.27", "autor": "Kiln (https://kiln.fi)", "license": "BUSL-1.1", "description": "JavaScript sdk for Kiln API", diff --git a/src/fireblocks.ts b/src/fireblocks.ts index 7fa8f45..617f131 100644 --- a/src/fireblocks.ts +++ b/src/fireblocks.ts @@ -1646,14 +1646,11 @@ export class FireblocksService { /** * Sign a Trx transaction on Fireblocks */ - async signTrxTx( + async createTrxTx( integration: FireblocksIntegration, tx: components['schemas']['TRXUnsignedTx'], note?: string, - ): Promise<{ - signed_tx: { data: components['schemas']['TRXPreparedTx'] }; - fireblocks_tx: TransactionResponse; - }> { + ): Promise { const payload = { rawMessageData: { messages: [ @@ -1670,13 +1667,25 @@ export class FireblocksService { const fbSigner = this.getSigner(integration); const fbNote = note ? note : 'TRX tx from @kilnfi/sdk'; - const fbTx = await fbSigner.sign(payload, 'TRX', fbNote); + return await fbSigner.createTransaction(payload, 'TRX', fbNote); + } - if (!fbTx.signedMessages?.[0]?.signature) { + async waitForTrxTxCompletion( + integration: FireblocksIntegration, + tx: components['schemas']['TRXUnsignedTx'], + fbTx: TransactionResponse, + ): Promise<{ + signed_tx: { data: components['schemas']['TRXPreparedTx'] }; + fireblocks_tx: TransactionResponse; + }> { + const fbSigner = this.getSigner(integration); + const completedTx = await fbSigner.waitForTxCompletion(fbTx); + + if (!completedTx.signedMessages?.[0]?.signature) { throw new Error(ERRORS.MISSING_SIGNATURE); } - const signature = `${fbTx.signedMessages[0].signature.fullSig}0${fbTx.signedMessages[0].signature.v}`; + const signature = `${completedTx.signedMessages[0].signature.fullSig}0${completedTx.signedMessages[0].signature.v}`; const preparedTx = await this.client.POST('/trx/transaction/prepare', { body: { @@ -1691,10 +1700,22 @@ export class FireblocksService { return { signed_tx: preparedTx.data, - fireblocks_tx: fbTx, + fireblocks_tx: completedTx, }; } + async signTrxTx( + integration: FireblocksIntegration, + tx: components['schemas']['TRXUnsignedTx'], + note?: string, + ): Promise<{ + signed_tx: { data: components['schemas']['TRXPreparedTx'] }; + fireblocks_tx: TransactionResponse; + }> { + const fbTx = await this.createTrxTx(integration, tx, note); + return await this.waitForTrxTxCompletion(integration, tx, fbTx); + } + /** * Sign a SEI transaction on Fireblocks */