Skip to content

Commit 7bc4a73

Browse files
authored
update fireblocks to ts-sdk (#185)
* update fireblocks to ts-sdk * bump
1 parent 65a152f commit 7bc4a73

File tree

4 files changed

+95
-109
lines changed

4 files changed

+95
-109
lines changed

bun.lockb

-25.9 KB
Binary file not shown.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kilnfi/sdk",
3-
"version": "4.0.7",
3+
"version": "4.1.0",
44
"autor": "Kiln <[email protected]> (https://kiln.fi)",
55
"license": "BUSL-1.1",
66
"description": "JavaScript sdk for Kiln API",
@@ -34,9 +34,9 @@
3434
},
3535
"homepage": "https://github.com/kilnfi/sdk-js#readme",
3636
"dependencies": {
37+
"@fireblocks/ts-sdk": "^6.0.0",
3738
"@types/bun": "^1.1.11",
3839
"bech32": "^2.0.0",
39-
"fireblocks-sdk": "^5.32.0",
4040
"openapi-fetch": "^0.12.0",
4141
"viem": "^2.21.29"
4242
},

src/fireblocks.ts

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
import {
22
type AssetTypeResponse,
3-
FireblocksSDK,
4-
type PublicKeyResponse,
5-
type SDKOptions,
6-
SigningAlgorithm,
3+
type ConfigurationOptions,
4+
Fireblocks,
5+
type PublicKeyInformation,
6+
SignedMessageAlgorithmEnum,
77
type TransactionResponse,
8-
} from 'fireblocks-sdk';
9-
import type { IAuthProvider } from 'fireblocks-sdk/dist/src/iauth-provider.js';
8+
} from '@fireblocks/ts-sdk';
9+
1010
import type { Client } from 'openapi-fetch';
1111
import { FireblocksSigner } from './fireblocks_signer.js';
1212
import type { components, paths } from './openapi/schema.js';
1313

14-
export type FireblocksIntegration = {
15-
provider: 'fireblocks';
16-
fireblocksApiKey: string;
17-
fireblocksSecretKey: string;
18-
vaultId: number;
19-
name?: string;
20-
fireblocksDestinationId?: string;
21-
fireblocksApiBaseUrl?: string;
22-
fireblocksAuthProvider?: IAuthProvider;
23-
fireblocksSdkOptions?: SDKOptions;
14+
export type FireblocksIntegration = (
15+
| { config?: never; instance: Fireblocks }
16+
| { config: ConfigurationOptions; instance?: never }
17+
) & {
18+
vaultId: `${number}`;
2419
};
2520

2621
export class FireblocksService {
@@ -33,14 +28,11 @@ export class FireblocksService {
3328
/**
3429
* Retrieve a fireblocks SDK from a Fireblocks integration
3530
*/
36-
getSdk(integration: FireblocksIntegration): FireblocksSDK {
37-
return new FireblocksSDK(
38-
integration.fireblocksSecretKey,
39-
integration.fireblocksApiKey,
40-
integration.fireblocksApiBaseUrl,
41-
integration.fireblocksAuthProvider,
42-
integration.fireblocksSdkOptions,
43-
);
31+
getSdk(integration: FireblocksIntegration): Fireblocks {
32+
if (integration.instance) {
33+
return integration.instance;
34+
}
35+
return new Fireblocks(integration.config);
4436
}
4537

4638
/**
@@ -54,24 +46,24 @@ export class FireblocksService {
5446
/**
5547
* Get fireblocks wallet pubkey compressed
5648
*/
57-
async getPubkey(integration: FireblocksIntegration, assetId: string): Promise<PublicKeyResponse> {
49+
async getPubkey(integration: FireblocksIntegration, assetId: string): Promise<PublicKeyInformation> {
5850
const fbSdk = this.getSdk(integration);
59-
const data = await fbSdk.getPublicKeyInfoForVaultAccount({
51+
const data = await fbSdk.vaults.getPublicKeyInfoForAddress({
6052
assetId: assetId,
6153
vaultAccountId: integration.vaultId,
6254
change: 0,
6355
addressIndex: 0,
6456
compressed: true,
6557
});
66-
return data;
58+
return data.data;
6759
}
6860

6961
/**
7062
* List Fireblocks supported assets
7163
*/
7264
async getAssets(integration: FireblocksIntegration): Promise<AssetTypeResponse[]> {
7365
const fbSdk = this.getSdk(integration);
74-
return await fbSdk.getSupportedAssets();
66+
return (await fbSdk.blockchainsAssets.getSupportedAssets()).data;
7567
}
7668

7769
/**
@@ -101,8 +93,9 @@ export class FireblocksService {
10193
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
10294

10395
const signatures = fbTx.signedMessages
104-
?.filter((signedMessage) => signedMessage.derivationPath[3] === 0)
105-
.map((signedMessage) => signedMessage.signature.fullSig);
96+
?.filter((signedMessage) => signedMessage.derivationPath?.[3] === 0)
97+
.map((signedMessage) => signedMessage.signature?.fullSig)
98+
.filter((s) => s !== undefined);
10699
if (!signatures) {
107100
throw new Error('Fireblocks signature is missing');
108101
}
@@ -156,12 +149,10 @@ export class FireblocksService {
156149
const fbNote = note ? note : 'ADA tx from @kilnfi/sdk';
157150
const fbTx = await fbSigner.sign(payload, 'ADA', fbNote);
158151

159-
const signedMessages = fbTx.signedMessages?.map((message) => {
160-
return {
161-
pubkey: message.publicKey,
162-
signature: message.signature.fullSig,
163-
};
164-
});
152+
const signedMessages = fbTx.signedMessages?.map((message) => ({
153+
pubkey: message.publicKey as string,
154+
signature: message.signature?.fullSig as string,
155+
}));
165156
if (!signedMessages) {
166157
throw new Error('Fireblocks signature is missing');
167158
}
@@ -211,7 +202,7 @@ export class FireblocksService {
211202
const fbSigner = this.getSigner(integration);
212203
const fbNote = note ? note : 'ATOM tx from @kilnfi/sdk';
213204
const fbTx = await fbSigner.sign(payload, 'ATOM_COS', fbNote);
214-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
205+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
215206

216207
if (!signature) {
217208
throw new Error('Fireblocks signature is missing');
@@ -264,7 +255,7 @@ export class FireblocksService {
264255
const fbSigner = this.getSigner(integration);
265256
const fbNote = note ? note : 'DYDX tx from @kilnfi/sdk';
266257
const fbTx = await fbSigner.sign(payload, 'DYDX_DYDX', fbNote);
267-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
258+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
268259

269260
if (!signature) {
270261
throw new Error('Fireblocks signature is missing');
@@ -312,14 +303,14 @@ export class FireblocksService {
312303
},
313304
},
314305
],
315-
algorithm: SigningAlgorithm.MPC_ECDSA_SECP256K1,
306+
algorithm: SignedMessageAlgorithmEnum.EcdsaSecp256K1,
316307
},
317308
};
318309

319310
const fbSigner = this.getSigner(integration);
320311
const fbNote = note ? note : 'FET tx from @kilnfi/sdk';
321312
const fbTx = await fbSigner.sign(payload, undefined, fbNote);
322-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
313+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
323314

324315
if (!signature) {
325316
throw new Error('Fireblocks signature is missing');
@@ -367,14 +358,14 @@ export class FireblocksService {
367358
},
368359
},
369360
],
370-
algorithm: SigningAlgorithm.MPC_ECDSA_SECP256K1,
361+
algorithm: SignedMessageAlgorithmEnum.EcdsaSecp256K1,
371362
},
372363
};
373364

374365
const fbSigner = this.getSigner(integration);
375366
const fbNote = note ? note : 'OM tx from @kilnfi/sdk';
376367
const fbTx = await fbSigner.sign(payload, undefined, fbNote);
377-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
368+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
378369

379370
if (!signature) {
380371
throw new Error('Fireblocks signature is missing');
@@ -427,7 +418,7 @@ export class FireblocksService {
427418
const fbSigner = this.getSigner(integration);
428419
const fbNote = note ? note : 'INJ tx from @kilnfi/sdk';
429420
const fbTx = await fbSigner.sign(payload, 'INJ_INJ', fbNote);
430-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
421+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
431422

432423
if (!signature) {
433424
throw new Error('Fireblocks signature is missing');
@@ -475,14 +466,14 @@ export class FireblocksService {
475466
},
476467
},
477468
],
478-
algorithm: SigningAlgorithm.MPC_ECDSA_SECP256K1,
469+
algorithm: SignedMessageAlgorithmEnum.EcdsaSecp256K1,
479470
},
480471
};
481472

482473
const fbSigner = this.getSigner(integration);
483474
const fbNote = note ? note : 'KAVA tx from @kilnfi/sdk';
484475
const fbTx = await fbSigner.sign(payload, undefined, fbNote);
485-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
476+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
486477

487478
if (!signature) {
488479
throw new Error('Fireblocks signature is missing');
@@ -530,14 +521,14 @@ export class FireblocksService {
530521
},
531522
},
532523
],
533-
algorithm: SigningAlgorithm.MPC_ECDSA_SECP256K1,
524+
algorithm: SignedMessageAlgorithmEnum.EcdsaSecp256K1,
534525
},
535526
};
536527

537528
const fbSigner = this.getSigner(integration);
538529
const fbNote = note ? note : 'NOBLE tx from @kilnfi/sdk';
539530
const fbTx = await fbSigner.sign(payload, undefined, fbNote);
540-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
531+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
541532

542533
if (!signature) {
543534
throw new Error('Fireblocks signature is missing');
@@ -590,7 +581,7 @@ export class FireblocksService {
590581
const fbSigner = this.getSigner(integration);
591582
const fbNote = note ? note : 'OSMO tx from @kilnfi/sdk';
592583
const fbTx = await fbSigner.sign(payload, 'OSMO', fbNote);
593-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
584+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
594585

595586
if (!signature) {
596587
throw new Error('Fireblocks signature is missing');
@@ -643,7 +634,7 @@ export class FireblocksService {
643634
const fbSigner = this.getSigner(integration);
644635
const fbNote = note ? note : 'TIA tx from @kilnfi/sdk';
645636
const fbTx = await fbSigner.sign(payload, 'CELESTIA', fbNote);
646-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
637+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
647638

648639
if (!signature) {
649640
throw new Error('Fireblocks signature is missing');
@@ -691,14 +682,14 @@ export class FireblocksService {
691682
},
692683
},
693684
],
694-
algorithm: SigningAlgorithm.MPC_ECDSA_SECP256K1,
685+
algorithm: SignedMessageAlgorithmEnum.EcdsaSecp256K1,
695686
},
696687
};
697688

698689
const fbSigner = this.getSigner(integration);
699690
const fbNote = note ? note : 'ZETA tx from @kilnfi/sdk';
700691
const fbTx = await fbSigner.sign(payload, undefined, fbNote);
701-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
692+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
702693

703694
if (!signature) {
704695
throw new Error('Fireblocks signature is missing');
@@ -747,6 +738,11 @@ export class FireblocksService {
747738
const fbSigner = this.getSigner(integration);
748739
const fbNote = note ? note : 'DOT tx from @kilnfi/sdk';
749740
const fbTx = await fbSigner.sign(payload, 'DOT', fbNote);
741+
742+
if (!fbTx.signedMessages?.[0]?.signature?.fullSig) {
743+
throw new Error('Fireblocks signature is missing');
744+
}
745+
750746
const signature = `0x00${fbTx.signedMessages?.[0]?.signature.fullSig}`;
751747

752748
const preparedTx = await this.client.POST('/dot/transaction/prepare', {
@@ -790,6 +786,11 @@ export class FireblocksService {
790786
const fbSigner = this.getSigner(integration);
791787
const fbNote = note ? note : 'KSM tx from @kilnfi/sdk';
792788
const fbTx = await fbSigner.sign(payload, 'KSM', fbNote);
789+
790+
if (!fbTx.signedMessages?.[0]?.signature?.fullSig) {
791+
throw new Error('Fireblocks signature is missing');
792+
}
793+
793794
const signature = `0x00${fbTx.signedMessages?.[0]?.signature.fullSig}`;
794795

795796
const preparedTx = await this.client.POST('/ksm/transaction/prepare', {
@@ -871,18 +872,16 @@ export class FireblocksService {
871872
integration: FireblocksIntegration,
872873
tx: components['schemas']['ETHUnsignedTx'],
873874
assetId: 'ETH_TEST6' | 'ETH',
875+
fireblocksDestinationId: string,
874876
note?: string,
875877
) {
876-
if (!integration.fireblocksDestinationId) {
877-
throw new Error('Fireblocks destination id is missing');
878-
}
879878
const payload = {
880879
contractCallData: tx.contract_call_data,
881880
};
882881

883882
const fbSigner = this.getSigner(integration);
884883
const fbNote = note ? note : 'ETH tx from @kilnfi/sdk';
885-
return await fbSigner.signAndBroadcastWith(payload, assetId, tx, integration.fireblocksDestinationId, true, fbNote);
884+
return await fbSigner.signAndBroadcastWith(payload, assetId, tx, fireblocksDestinationId, true, fbNote);
886885
}
887886

888887
/**
@@ -947,18 +946,16 @@ export class FireblocksService {
947946
integration: FireblocksIntegration,
948947
tx: components['schemas']['POLUnsignedTx'],
949948
assetId: 'ETH_TEST5' | 'ETH',
949+
fireblocksDestinationId: string,
950950
note?: string,
951951
) {
952-
if (!integration.fireblocksDestinationId) {
953-
throw new Error('Fireblocks destination id is missing');
954-
}
955952
const payload = {
956953
contractCallData: tx.contract_call_data,
957954
};
958955

959956
const fbSigner = this.getSigner(integration);
960957
const fbNote = note ? note : 'POL tx from @kilnfi/sdk';
961-
return await fbSigner.signAndBroadcastWith(payload, assetId, tx, integration.fireblocksDestinationId, true, fbNote);
958+
return await fbSigner.signAndBroadcastWith(payload, assetId, tx, fireblocksDestinationId, true, fbNote);
962959
}
963960

964961
/**
@@ -986,7 +983,7 @@ export class FireblocksService {
986983
const fbSigner = this.getSigner(integration);
987984
const fbNote = note ? note : 'TON tx from @kilnfi/sdk';
988985
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
989-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
986+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
990987

991988
if (!signature) {
992989
throw new Error('Fireblocks signature is missing');
@@ -1035,7 +1032,7 @@ export class FireblocksService {
10351032
const fbSigner = this.getSigner(integration);
10361033
const fbNote = note ? note : 'XTZ tx from @kilnfi/sdk';
10371034
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
1038-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
1035+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
10391036

10401037
if (!signature) {
10411038
throw new Error('Fireblocks signature is missing');
@@ -1083,7 +1080,7 @@ export class FireblocksService {
10831080
const fbSigner = this.getSigner(integration);
10841081
const fbNote = note ? note : 'NEAR tx from @kilnfi/sdk';
10851082
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
1086-
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
1083+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
10871084

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

0 commit comments

Comments
 (0)