|
1 | 1 | import { type AssetTypeResponse, FireblocksSDK, type PublicKeyResponse, SigningAlgorithm } from 'fireblocks-sdk'; |
2 | 2 | import type { Client } from 'openapi-fetch'; |
3 | | -import { FireblocksSigner } from './fireblocks_signer'; |
4 | | -import type { components, paths } from './openapi/schema'; |
| 3 | +import { FireblocksSigner } from './fireblocks_signer.js'; |
| 4 | +import type { components, paths } from './openapi/schema.js'; |
5 | 5 |
|
6 | 6 | export type FireblocksIntegration = { |
7 | 7 | provider: 'fireblocks'; |
@@ -189,7 +189,8 @@ export class FireblocksService { |
189 | 189 | const fbSigner = this.getSigner(integration); |
190 | 190 | const fbNote = note ? note : 'ATOM tx from @kilnfi/sdk'; |
191 | 191 | const fbTx = await fbSigner.sign(payload, assetId, fbNote); |
192 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 192 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 193 | + |
193 | 194 | if (!signature) { |
194 | 195 | throw new Error('Fireblocks signature is missing'); |
195 | 196 | } |
@@ -237,7 +238,8 @@ export class FireblocksService { |
237 | 238 | const fbSigner = this.getSigner(integration); |
238 | 239 | const fbNote = note ? note : 'DYDX tx from @kilnfi/sdk'; |
239 | 240 | const fbTx = await fbSigner.sign(payload, 'DYDX_DYDX', fbNote); |
240 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 241 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 242 | + |
241 | 243 | if (!signature) { |
242 | 244 | throw new Error('Fireblocks signature is missing'); |
243 | 245 | } |
@@ -287,7 +289,8 @@ export class FireblocksService { |
287 | 289 | const fbSigner = this.getSigner(integration); |
288 | 290 | const fbNote = note ? note : 'FET tx from @kilnfi/sdk'; |
289 | 291 | const fbTx = await fbSigner.sign(payload, undefined, fbNote); |
290 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 292 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 293 | + |
291 | 294 | if (!signature) { |
292 | 295 | throw new Error('Fireblocks signature is missing'); |
293 | 296 | } |
@@ -335,7 +338,8 @@ export class FireblocksService { |
335 | 338 | const fbSigner = this.getSigner(integration); |
336 | 339 | const fbNote = note ? note : 'INJ tx from @kilnfi/sdk'; |
337 | 340 | const fbTx = await fbSigner.sign(payload, 'INJ_INJ', fbNote); |
338 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 341 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 342 | + |
339 | 343 | if (!signature) { |
340 | 344 | throw new Error('Fireblocks signature is missing'); |
341 | 345 | } |
@@ -383,7 +387,8 @@ export class FireblocksService { |
383 | 387 | const fbSigner = this.getSigner(integration); |
384 | 388 | const fbNote = note ? note : 'KAVA tx from @kilnfi/sdk'; |
385 | 389 | const fbTx = await fbSigner.sign(payload, 'KAVA_KAVA', fbNote); |
386 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 390 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 391 | + |
387 | 392 | if (!signature) { |
388 | 393 | throw new Error('Fireblocks signature is missing'); |
389 | 394 | } |
@@ -431,7 +436,8 @@ export class FireblocksService { |
431 | 436 | const fbSigner = this.getSigner(integration); |
432 | 437 | const fbNote = note ? note : 'OSMO tx from @kilnfi/sdk'; |
433 | 438 | const fbTx = await fbSigner.sign(payload, 'OSMO', fbNote); |
434 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 439 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 440 | + |
435 | 441 | if (!signature) { |
436 | 442 | throw new Error('Fireblocks signature is missing'); |
437 | 443 | } |
@@ -479,7 +485,8 @@ export class FireblocksService { |
479 | 485 | const fbSigner = this.getSigner(integration); |
480 | 486 | const fbNote = note ? note : 'TIA tx from @kilnfi/sdk'; |
481 | 487 | const fbTx = await fbSigner.sign(payload, 'CELESTIA', fbNote); |
482 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 488 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 489 | + |
483 | 490 | if (!signature) { |
484 | 491 | throw new Error('Fireblocks signature is missing'); |
485 | 492 | } |
@@ -529,7 +536,8 @@ export class FireblocksService { |
529 | 536 | const fbSigner = this.getSigner(integration); |
530 | 537 | const fbNote = note ? note : 'ZETA tx from @kilnfi/sdk'; |
531 | 538 | const fbTx = await fbSigner.sign(payload, undefined, fbNote); |
532 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 539 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 540 | + |
533 | 541 | if (!signature) { |
534 | 542 | throw new Error('Fireblocks signature is missing'); |
535 | 543 | } |
@@ -569,7 +577,7 @@ export class FireblocksService { |
569 | 577 | const fbSigner = this.getSigner(integration); |
570 | 578 | const fbNote = note ? note : 'DOT tx from @kilnfi/sdk'; |
571 | 579 | const fbTx = await fbSigner.sign(payload, 'DOT', fbNote); |
572 | | - const signature = `0x00${fbTx.signedMessages?.[0].signature.fullSig}`; |
| 580 | + const signature = `0x00${fbTx.signedMessages?.[0]?.signature.fullSig}`; |
573 | 581 |
|
574 | 582 | const preparedTx = await this.client.POST('/v1/dot/transaction/prepare', { |
575 | 583 | body: { |
@@ -604,7 +612,7 @@ export class FireblocksService { |
604 | 612 | const fbSigner = this.getSigner(integration); |
605 | 613 | const fbNote = note ? note : 'KSM tx from @kilnfi/sdk'; |
606 | 614 | const fbTx = await fbSigner.sign(payload, 'KSM', fbNote); |
607 | | - const signature = `0x00${fbTx.signedMessages?.[0].signature.fullSig}`; |
| 615 | + const signature = `0x00${fbTx.signedMessages?.[0]?.signature.fullSig}`; |
608 | 616 |
|
609 | 617 | const preparedTx = await this.client.POST('/v1/ksm/transaction/prepare', { |
610 | 618 | body: { |
@@ -650,12 +658,18 @@ export class FireblocksService { |
650 | 658 | const fbNote = note ? note : 'ETH tx from @kilnfi/sdk'; |
651 | 659 | const fbTx = await fbSigner.sign(payload, assetId, fbNote); |
652 | 660 |
|
| 661 | + const signature = fbTx?.signedMessages?.[0]?.signature; |
| 662 | + |
| 663 | + if (!signature) { |
| 664 | + throw new Error('Fireblocks signature is missing'); |
| 665 | + } |
| 666 | + |
653 | 667 | const preparedTx = await this.client.POST('/v1/eth/transaction/prepare', { |
654 | 668 | body: { |
655 | 669 | unsigned_tx_serialized: tx.unsigned_tx_serialized, |
656 | | - r: `0x${fbTx?.signedMessages?.[0].signature.r}`, |
657 | | - s: `0x${fbTx?.signedMessages?.[0].signature.s}`, |
658 | | - v: fbTx?.signedMessages?.[0].signature.v ?? 0, |
| 670 | + r: `0x${signature.r}`, |
| 671 | + s: `0x${signature.s}`, |
| 672 | + v: signature.v ?? 0, |
659 | 673 | }, |
660 | 674 | }); |
661 | 675 |
|
@@ -741,7 +755,11 @@ export class FireblocksService { |
741 | 755 | const fbSigner = this.getSigner(integration); |
742 | 756 | const fbNote = note ? note : 'TON tx from @kilnfi/sdk'; |
743 | 757 | const fbTx = await fbSigner.sign(payload, assetId, fbNote); |
744 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 758 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
| 759 | + |
| 760 | + if (!signature) { |
| 761 | + throw new Error('Fireblocks signature is missing'); |
| 762 | + } |
745 | 763 |
|
746 | 764 | const preparedTx = await this.client.POST('/v1/ton/transaction/prepare', { |
747 | 765 | body: { |
@@ -783,7 +801,7 @@ export class FireblocksService { |
783 | 801 | const fbSigner = this.getSigner(integration); |
784 | 802 | const fbNote = note ? note : 'XTZ tx from @kilnfi/sdk'; |
785 | 803 | const fbTx = await fbSigner.sign(payload, assetId, fbNote); |
786 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 804 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
787 | 805 |
|
788 | 806 | if (!signature) { |
789 | 807 | throw new Error('Fireblocks signature is missing'); |
@@ -828,7 +846,7 @@ export class FireblocksService { |
828 | 846 | const fbSigner = this.getSigner(integration); |
829 | 847 | const fbNote = note ? note : 'NEAR tx from @kilnfi/sdk'; |
830 | 848 | const fbTx = await fbSigner.sign(payload, assetId, fbNote); |
831 | | - const signature = fbTx.signedMessages?.[0].signature.fullSig; |
| 849 | + const signature = fbTx.signedMessages?.[0]?.signature.fullSig; |
832 | 850 |
|
833 | 851 | if (!signature) { |
834 | 852 | throw new Error('Fireblocks signature is missing'); |
|
0 commit comments