Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add signPolTx with raw signing #156

Merged
merged 1 commit into from
Nov 14, 2024
Merged
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
57 changes: 56 additions & 1 deletion src/fireblocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ export class FireblocksService {
}

/**
* Sign and broadcast an ETH transaction with given integration using Fireblocks contract call feature
* Sign an ETH transaction with given integration using Fireblocks raw signing
*/
async signEthTx(
integration: FireblocksIntegration,
Expand Down Expand Up @@ -831,6 +831,61 @@ export class FireblocksService {
return await fbSigner.signAndBroadcastWith(payload, assetId, tx, integration.fireblocksDestinationId, true, fbNote);
}

/**
* Sign a POL transaction with given integration using Fireblocks raw signing
*/
async signPolTx(
integration: FireblocksIntegration,
tx: components['schemas']['POLUnsignedTx'],
assetId: 'ETH_TEST5' | 'ETH',
note?: string,
): Promise<{
signed_tx: { data: components['schemas']['POLSignedTx'] };
fireblocks_tx: TransactionResponse;
}> {
const payload = {
rawMessageData: {
messages: [
{
content: tx.unsigned_tx_hash,
preHash: {
content: tx.unsigned_tx_serialized,
hashAlgorithm: 'KECCAK256',
},
},
],
},
};

const fbSigner = this.getSigner(integration);
const fbNote = note ? note : 'POL tx from @kilnfi/sdk';
const fbTx = await fbSigner.sign(payload, assetId, fbNote);

const signature = fbTx?.signedMessages?.[0]?.signature;

if (!signature) {
throw new Error('Fireblocks signature is missing');
}

const preparedTx = await this.client.POST('/v1/pol/transaction/prepare', {
body: {
unsigned_tx_serialized: tx.unsigned_tx_serialized,
r: `0x${signature.r}`,
s: `0x${signature.s}`,
v: signature.v ?? 0,
},
});

if (preparedTx.error) {
throw new Error('Failed to prepare transaction');
}

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

/**
* Sign and broadcast a POL transaction with given integration using Fireblocks contract call feature
*/
Expand Down