Skip to content

Commit eedb760

Browse files
committed
feat ada tx handling fireblocks
1 parent ecb7dff commit eedb760

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/fireblocks.ts

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,29 @@ export class FireblocksService {
127127
}
128128

129129
/**
130-
* Sign a Cardano transaction on Fireblocks
130+
* Create a Cardano transaction in Fireblocks without waiting for completion
131131
*/
132-
async signAdaTx(
132+
async createAdaTx(
133133
integration: FireblocksIntegration,
134134
tx: components['schemas']['ADAUnsignedTx'],
135135
note?: string,
136-
): Promise<{
137-
signed_tx: { data: components['schemas']['ADASignedTx'] };
138-
fireblocks_tx: TransactionResponse;
139-
}> {
136+
): Promise<TransactionResponse> {
140137
const payload = {
141138
rawMessageData: {
142139
messages: [
143140
{
144141
content: tx.unsigned_tx_hash,
142+
preHash: {
143+
content: tx.unsigned_tx_body_serialized,
144+
hashAlgorithm: 'BLAKE2',
145+
},
145146
},
146147
{
147148
content: tx.unsigned_tx_hash,
149+
preHash: {
150+
content: tx.unsigned_tx_body_serialized,
151+
hashAlgorithm: 'BLAKE2',
152+
},
148153
bip44change: 2,
149154
},
150155
],
@@ -156,12 +161,27 @@ export class FireblocksService {
156161

157162
const fbSigner = this.getSigner(integration);
158163
const fbNote = note ? note : 'ADA tx from @kilnfi/sdk';
159-
const fbTx = await fbSigner.sign(payload, 'ADA', fbNote);
164+
return await fbSigner.createTransaction(payload, 'ADA', fbNote);
165+
}
160166

161-
const signedMessages = fbTx.signedMessages?.map((message) => ({
167+
/**
168+
* Wait for a Cardano transaction to complete and prepare it for broadcast
169+
*/
170+
async waitForAdaTxCompletion(
171+
integration: FireblocksIntegration,
172+
tx: components['schemas']['ADAUnsignedTx'],
173+
fbTx: TransactionResponse,
174+
): Promise<{
175+
signed_tx: { data: components['schemas']['ADASignedTx'] };
176+
fireblocks_tx: TransactionResponse;
177+
}> {
178+
const fbSigner = this.getSigner(integration);
179+
const completedTx = await fbSigner.waitForTxCompletion(fbTx);
180+
const signedMessages = completedTx.signedMessages?.map((message) => ({
162181
pubkey: message.publicKey as string,
163182
signature: message.signature?.fullSig as string,
164183
}));
184+
165185
if (!signedMessages) {
166186
throw new Error(ERRORS.MISSING_SIGNATURE);
167187
}
@@ -179,10 +199,25 @@ export class FireblocksService {
179199

180200
return {
181201
signed_tx: preparedTx.data,
182-
fireblocks_tx: fbTx,
202+
fireblocks_tx: completedTx,
183203
};
184204
}
185205

206+
/**
207+
* Sign a Cardano transaction on Fireblocks
208+
*/
209+
async signAdaTx(
210+
integration: FireblocksIntegration,
211+
tx: components['schemas']['ADAUnsignedTx'],
212+
note?: string,
213+
): Promise<{
214+
signed_tx: { data: components['schemas']['ADASignedTx'] };
215+
fireblocks_tx: TransactionResponse;
216+
}> {
217+
const fbTx = await this.createAdaTx(integration, tx, note);
218+
return await this.waitForAdaTxCompletion(integration, tx, fbTx);
219+
}
220+
186221
/**
187222
* Create an ATOM transaction in Fireblocks without waiting for completion
188223
*/

0 commit comments

Comments
 (0)