Skip to content

Commit

Permalink
add fireblocks tx in response of sign() functions (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
nooxx authored Nov 24, 2023
1 parent 12ca4bc commit 598930d
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/services/ada.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export class AdaService extends Service {
unsigned_tx_serialized: tx.data.unsigned_tx_serialized,
signed_messages: signedMessages,
});

data.data.fireblocks_tx = fbTx;
return data;
} catch (err: any) {
throw new Error(err);
Expand Down
5 changes: 3 additions & 2 deletions src/services/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export class AtomService extends Service {
};
const fbNote = note ? note : 'ATOM tx from @kilnfi/sdk';
const signer = this.getFbSigner(integration);
const signedTx = await signer.signWithFB(payload, this.testnet ? 'ATOM_COS_TEST' : 'ATOM_COS', fbNote);
const signature: string = signedTx.signedMessages![0].signature.fullSig;
const fbTx = await signer.signWithFB(payload, this.testnet ? 'ATOM_COS_TEST' : 'ATOM_COS', fbNote);
const signature: string = fbTx.signedMessages![0].signature.fullSig;
const { data } = await api.post<AtomSignedTx>(
`/v1/atom/transaction/prepare`,
{
Expand All @@ -160,6 +160,7 @@ export class AtomService extends Service {
tx_auth_info: tx.data.tx_auth_info,
signature: signature,
});
data.data.fireblocks_tx = fbTx;
return data;
}

Expand Down
5 changes: 3 additions & 2 deletions src/services/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,16 @@ export class DotService extends Service {

const fbSigner = this.getFbSigner(integration);
const fbNote = note ? note : 'DOT tx from @kilnfi/sdk';
const fbSignatures = await fbSigner.signWithFB(payload, this.testnet ? 'WND' : 'DOT', fbNote);
const signature = `0x00${fbSignatures.signedMessages![0].signature.fullSig}`;
const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'WND' : 'DOT', fbNote);
const signature = `0x00${fbTx.signedMessages![0].signature.fullSig}`;

const { data } = await api.post<DotSignedTx>(
`/v1/dot/transaction/prepare`,
{
unsigned_tx_serialized: tx.data.unsigned_tx_serialized,
signature: signature,
});
data.data.fireblocks_tx = fbTx;
return data;
} catch (err: any) {
throw new Error(err);
Expand Down
9 changes: 5 additions & 4 deletions src/services/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class EthService extends Service {
const fbSigner = this.getFbSigner(integration);
const assetId = this.testnet ? 'ETH_TEST6' : 'ETH';
const fbNote = note ? note : 'ETH tx from @kilnfi/sdk';
const signatures = await fbSigner.signWithFB(
const fbTx = await fbSigner.signWithFB(
payload,
assetId,
fbNote,
Expand All @@ -97,10 +97,11 @@ export class EthService extends Service {
`/v1/eth/transaction/prepare`,
{
unsigned_tx_serialized: tx.data.unsigned_tx_serialized,
r: `0x${signatures?.signedMessages?.[0].signature.r}`,
s: `0x${signatures?.signedMessages?.[0].signature.s}`,
v: signatures?.signedMessages?.[0].signature.v ?? 0,
r: `0x${fbTx?.signedMessages?.[0].signature.r}`,
s: `0x${fbTx?.signedMessages?.[0].signature.s}`,
v: fbTx?.signedMessages?.[0].signature.v ?? 0,
});
data.data.fireblocks_tx = fbTx;
return data;
} catch (err: any) {
throw new Error(err);
Expand Down
9 changes: 5 additions & 4 deletions src/services/matic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,16 @@ export class MaticService extends Service {

const fbSigner = this.getFbSigner(integration);
const fbNote = note ? note : 'MATIC tx from @kilnfi/sdk';
const signatures = await fbSigner.signWithFB(payload, this.testnet ? 'ETH_TEST3' : 'ETH', fbNote);
const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'ETH_TEST3' : 'ETH', fbNote);
const { data } = await api.post<MaticSignedTx>(
`/v1/matic/transaction/prepare`,
{
unsigned_tx_serialized: tx.data.unsigned_tx_serialized,
r: `0x${signatures?.signedMessages?.[0].signature.r}`,
s: `0x${signatures?.signedMessages?.[0].signature.s}`,
v: signatures?.signedMessages?.[0].signature.v ?? 0,
r: `0x${fbTx?.signedMessages?.[0].signature.r}`,
s: `0x${fbTx?.signedMessages?.[0].signature.s}`,
v: fbTx?.signedMessages?.[0].signature.v ?? 0,
});
data.data.fireblocks_tx = fbTx;
return data;
} catch (err: any) {
throw new Error(err);
Expand Down
5 changes: 3 additions & 2 deletions src/services/near.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ export class NearService extends Service {

const fbSigner = this.getFbSigner(integration);
const fbNote = note ? note : 'NEAR tx from @kilnfi/sdk';
const signatures = await fbSigner.signWithFB(payload, this.testnet ? 'NEAR_TEST' : 'NEAR', fbNote);
const signature = signatures.signedMessages![0];
const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'NEAR_TEST' : 'NEAR', fbNote);
const signature = fbTx.signedMessages![0];

const signedTx = new transactions.SignedTransaction({
transaction: tx.data.tx,
Expand All @@ -253,6 +253,7 @@ export class NearService extends Service {

return {
data: {
fireblocks_tx: fbTx,
tx: signedTx,
},
};
Expand Down
5 changes: 3 additions & 2 deletions src/services/osmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export class OsmoService extends Service {
};
const fbNote = note ? note : 'OSMO tx from @kilnfi/sdk';
const signer = this.getFbSigner(integration);
const signedTx = await signer.signWithFB(payload, this.testnet ? 'OSMO_TEST' : 'OSMO', fbNote);
const signature: string = signedTx.signedMessages![0].signature.fullSig;
const fbTx = await signer.signWithFB(payload, this.testnet ? 'OSMO_TEST' : 'OSMO', fbNote);
const signature: string = fbTx.signedMessages![0].signature.fullSig;
const { data } = await api.post<OsmoSignedTx>(
`/v1/osmo/transaction/prepare`,
{
Expand All @@ -160,6 +160,7 @@ export class OsmoService extends Service {
tx_auth_info: tx.data.tx_auth_info,
signature: signature,
});
data.data.fireblocks_tx = fbTx;
return data;
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class Service {

/**
* Retrieve a fireblocks SDK from a Fireblocks integration
* @param integration: Fireblocks integration
* @param integration
*/
getFbSdk(integration: FireblocksIntegration): FireblocksSDK {
try {
Expand All @@ -24,7 +24,7 @@ export class Service {

/**
* Retrieve a fireblocks signer from a Fireblocks integration
* @param integration: Fireblocks integration
* @param integration
*/
getFbSigner(integration: FireblocksIntegration): FbSigner {
try {
Expand Down
5 changes: 3 additions & 2 deletions src/services/sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ export class SolService extends Service {

const fbSigner = this.getFbSigner(integration);
const fbNote = note ? note : 'SOL tx from @kilnfi/sdk';
const fbSignatures = await fbSigner.signWithFB(payload, this.testnet ? 'SOL_TEST' : 'SOL', fbNote);
const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'SOL_TEST' : 'SOL', fbNote);
const signatures: string[] = [];
fbSignatures.signedMessages?.forEach((signedMessage: any) => {
fbTx.signedMessages?.forEach((signedMessage: any) => {
if (signedMessage.derivationPath[3] == 0) {
signatures.push(signedMessage.signature.fullSig);
}
Expand All @@ -185,6 +185,7 @@ export class SolService extends Service {
unsigned_tx_serialized: tx.data.unsigned_tx_serialized,
signatures: signatures,
});
data.data.fireblocks_tx = fbTx;
return data;
} catch (err: any) {
throw new Error(err);
Expand Down
5 changes: 3 additions & 2 deletions src/services/xtz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ export class XtzService extends Service {

const fbSigner = this.getFbSigner(integration);
const fbNote = note ? note : 'XTZ tx from @kilnfi/sdk';
const signedTx = await fbSigner.signWithFB(payload, this.testnet ? 'XTZ_TEST' : 'XTZ', fbNote);
const signature: string = signedTx.signedMessages![0].signature.fullSig;
const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'XTZ_TEST' : 'XTZ', fbNote);
const signature: string = fbTx.signedMessages![0].signature.fullSig;
const { data } = await api.post<XtzSignedTx>(
`/v1/xtz/transaction/prepare`,
{
unsigned_tx_serialized: tx.data.unsigned_tx_serialized,
signature: signature,
});
data.data.fireblocks_tx = fbTx;
return data;
}

Expand Down
2 changes: 2 additions & 0 deletions src/types/ada.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Responses } from '@blockfrost/blockfrost-js';
import {
TransactionInputsJSON,
} from '@emurgo/cardano-serialization-lib-nodejs';
import { TransactionResponse } from "fireblocks-sdk";

export type AdaTxStatus = {
data: {
Expand Down Expand Up @@ -43,6 +44,7 @@ export type AdaRewards = {

export type AdaSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
signed_tx_serialized: string;
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/types/atom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IndexedTx, StdFee } from "@cosmjs/stargate";
import { EncodeObject } from "@cosmjs/proto-signing";
import { TransactionResponse } from "fireblocks-sdk";

export type AtomTx = {
data: {
Expand All @@ -15,6 +16,7 @@ export type AtomTx = {

export type AtomSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
signed_tx_serialized: string;
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/types/dot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DecodedSigningPayload } from "@substrate/txwrapper-polkadot";
import { TransactionResponse } from "fireblocks-sdk";

/**
* 'Staked': Rewards are paid into the stash account, increasing the amount at stake accordingly.
Expand All @@ -18,6 +19,7 @@ export type DotTx = {

export type DotSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
signed_tx_serialized: string;
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/types/eth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TransactionReceipt } from 'web3-core';
import { TransactionResponse } from "fireblocks-sdk";

export type EthStakes = {
data: EthStake[]
Expand Down Expand Up @@ -102,6 +103,7 @@ export type EthTxStatus = {
}
export type EthSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
signed_tx_serialized: string;
};
};
2 changes: 2 additions & 0 deletions src/types/matic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TransactionReceipt } from 'web3-core';
import { TransactionResponse } from "fireblocks-sdk";

export type MaticTx = {
data: {
Expand Down Expand Up @@ -29,6 +30,7 @@ export type MaticTxStatus = {
}
export type MaticSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
signed_tx_serialized: string;
};
};
2 changes: 2 additions & 0 deletions src/types/near.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
import { SignedTransaction, Transaction } from 'near-api-js/lib/transaction';
import { TransactionResponse } from "fireblocks-sdk";

export type NearTx = {
data: {
Expand All @@ -9,6 +10,7 @@ export type NearTx = {

export type NearSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
tx: SignedTransaction
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/osmo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IndexedTx, StdFee } from "@cosmjs/stargate";
import { EncodeObject } from "@cosmjs/proto-signing";
import { TransactionResponse } from "fireblocks-sdk";

export type OsmoTx = {
data: {
Expand All @@ -15,6 +16,7 @@ export type OsmoTx = {

export type OsmoSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
signed_tx_serialized: string;
};
};
Expand Down
3 changes: 2 additions & 1 deletion src/types/sol.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TransactionResponse } from '@solana/web3.js';
import { TransactionResponse } from "fireblocks-sdk";

export type SolTx = {
data: {
Expand All @@ -9,6 +9,7 @@ export type SolTx = {

export type SolSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
signed_tx_serialized: string;
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/types/xtz.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OperationEntry } from '@taquito/rpc';
import { TransactionResponse } from "fireblocks-sdk";

export type XtzTx = {
data: {
Expand All @@ -9,6 +10,7 @@ export type XtzTx = {

export type XtzSignedTx = {
data: {
fireblocks_tx: TransactionResponse;
signed_tx_serialized: string;
}
};
Expand Down

0 comments on commit 598930d

Please sign in to comment.