Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kilnfi/sdk",
"version": "4.2.23",
"version": "4.2.24",
"autor": "Kiln <support@kiln.fi> (https://kiln.fi)",
"license": "BUSL-1.1",
"description": "JavaScript sdk for Kiln API",
Expand Down
47 changes: 38 additions & 9 deletions src/fireblocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1385,31 +1385,44 @@ export class FireblocksService {
}

/**
* Sign a TON transaction on Fireblocks
* Create a TON transaction in Fireblocks without waiting for completion
*/
async signTonTx(
async createTonTx(
integration: FireblocksIntegration,
tx: components['schemas']['TONTx'],
assetId: 'TON_TEST' | 'TON',
note?: string,
): Promise<{
signed_tx: { data: components['schemas']['TONPreparedTx'] };
fireblocks_tx: TransactionResponse;
}> {
): Promise<TransactionResponse> {
const payload = {
rawMessageData: {
messages: [
{
content: tx.unsigned_tx_hash,
//TODO : ADD PREHASH LATER IF FB SUPPORT TON HASH ALGORITHM
},
],
},
};

const fbSigner = this.getSigner(integration);
const fbNote = note ? note : 'TON tx from @kilnfi/sdk';
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
return await fbSigner.createTransaction(payload, assetId, fbNote);
}

/**
* Wait for a TON transaction to complete and prepare it for broadcast
*/
async waitForTonTxCompletion(
integration: FireblocksIntegration,
tx: components['schemas']['TONTx'],
fbTx: TransactionResponse,
): Promise<{
signed_tx: { data: components['schemas']['TONPreparedTx'] };
fireblocks_tx: TransactionResponse;
}> {
const fbSigner = this.getSigner(integration);
const completedTx = await fbSigner.waitForTxCompletion(fbTx);
const signature = completedTx.signedMessages?.[0]?.signature?.fullSig;

if (!signature) {
throw new Error(ERRORS.MISSING_SIGNATURE);
Expand All @@ -1429,10 +1442,26 @@ export class FireblocksService {

return {
signed_tx: preparedTx.data,
fireblocks_tx: fbTx,
fireblocks_tx: completedTx,
};
}

/**
* Sign a TON transaction on Fireblocks
*/
async signTonTx(
integration: FireblocksIntegration,
tx: components['schemas']['TONTx'],
assetId: 'TON_TEST' | 'TON',
note?: string,
): Promise<{
signed_tx: { data: components['schemas']['TONPreparedTx'] };
fireblocks_tx: TransactionResponse;
}> {
const fbTx = await this.createTonTx(integration, tx, assetId, note);
return await this.waitForTonTxCompletion(integration, tx, fbTx);
}

/**
* Sign a XTZ transaction on Fireblocks
*/
Expand Down