Skip to content

Commit f0623cb

Browse files
committed
add ESM + CJS builds (#133)
1 parent 55b0b38 commit f0623cb

File tree

9 files changed

+122
-53
lines changed

9 files changed

+122
-53
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.DS_Store
22
node_modules/
3-
lib/
3+
build/
44
.idea/

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
{
22
"name": "@kilnfi/sdk",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"autor": "Kiln <[email protected]> (https://kiln.fi)",
55
"license": "BUSL-1.1",
66
"description": "JavaScript sdk for Kiln API",
77
"type": "module",
8+
"main": "./build/cjs/index.js",
9+
"module": "./build/esm/index.js",
10+
"types": "./build/types/index.d.ts",
11+
"typings": "./build/types/index.d.ts",
812
"exports": {
913
".": {
10-
"default": "./lib/kiln.js",
11-
"types": "./lib/kiln.d.ts",
12-
"import": "./lib/kiln.js"
14+
"default": "./build/cjs/kiln.js",
15+
"types": "./build/types/kiln.d.ts",
16+
"import": "./build/esm/kiln.js"
1317
}
1418
},
1519
"scripts": {
1620
"lint": "biome check ./src",
1721
"format": "biome check ./src --write --unsafe",
18-
"build": "tsc"
22+
"build": "bun run build:esm && bun run build:cjs && bun run build:types",
23+
"build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./build/esm",
24+
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./build/cjs --removeComments --verbatimModuleSyntax false",
25+
"build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./build/types --emitDeclarationOnly --declaration --declarationMap"
1926
},
2027
"keywords": [
2128
"sdk",

src/fireblocks.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type AssetTypeResponse, FireblocksSDK, type PublicKeyResponse, SigningAlgorithm } from 'fireblocks-sdk';
22
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';
55

66
export type FireblocksIntegration = {
77
provider: 'fireblocks';
@@ -189,7 +189,8 @@ export class FireblocksService {
189189
const fbSigner = this.getSigner(integration);
190190
const fbNote = note ? note : 'ATOM tx from @kilnfi/sdk';
191191
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+
193194
if (!signature) {
194195
throw new Error('Fireblocks signature is missing');
195196
}
@@ -237,7 +238,8 @@ export class FireblocksService {
237238
const fbSigner = this.getSigner(integration);
238239
const fbNote = note ? note : 'DYDX tx from @kilnfi/sdk';
239240
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+
241243
if (!signature) {
242244
throw new Error('Fireblocks signature is missing');
243245
}
@@ -287,7 +289,8 @@ export class FireblocksService {
287289
const fbSigner = this.getSigner(integration);
288290
const fbNote = note ? note : 'FET tx from @kilnfi/sdk';
289291
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+
291294
if (!signature) {
292295
throw new Error('Fireblocks signature is missing');
293296
}
@@ -335,7 +338,8 @@ export class FireblocksService {
335338
const fbSigner = this.getSigner(integration);
336339
const fbNote = note ? note : 'INJ tx from @kilnfi/sdk';
337340
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+
339343
if (!signature) {
340344
throw new Error('Fireblocks signature is missing');
341345
}
@@ -383,7 +387,8 @@ export class FireblocksService {
383387
const fbSigner = this.getSigner(integration);
384388
const fbNote = note ? note : 'KAVA tx from @kilnfi/sdk';
385389
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+
387392
if (!signature) {
388393
throw new Error('Fireblocks signature is missing');
389394
}
@@ -431,7 +436,8 @@ export class FireblocksService {
431436
const fbSigner = this.getSigner(integration);
432437
const fbNote = note ? note : 'OSMO tx from @kilnfi/sdk';
433438
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+
435441
if (!signature) {
436442
throw new Error('Fireblocks signature is missing');
437443
}
@@ -479,7 +485,8 @@ export class FireblocksService {
479485
const fbSigner = this.getSigner(integration);
480486
const fbNote = note ? note : 'TIA tx from @kilnfi/sdk';
481487
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+
483490
if (!signature) {
484491
throw new Error('Fireblocks signature is missing');
485492
}
@@ -529,7 +536,8 @@ export class FireblocksService {
529536
const fbSigner = this.getSigner(integration);
530537
const fbNote = note ? note : 'ZETA tx from @kilnfi/sdk';
531538
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+
533541
if (!signature) {
534542
throw new Error('Fireblocks signature is missing');
535543
}
@@ -569,7 +577,7 @@ export class FireblocksService {
569577
const fbSigner = this.getSigner(integration);
570578
const fbNote = note ? note : 'DOT tx from @kilnfi/sdk';
571579
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}`;
573581

574582
const preparedTx = await this.client.POST('/v1/dot/transaction/prepare', {
575583
body: {
@@ -604,7 +612,7 @@ export class FireblocksService {
604612
const fbSigner = this.getSigner(integration);
605613
const fbNote = note ? note : 'KSM tx from @kilnfi/sdk';
606614
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}`;
608616

609617
const preparedTx = await this.client.POST('/v1/ksm/transaction/prepare', {
610618
body: {
@@ -650,12 +658,18 @@ export class FireblocksService {
650658
const fbNote = note ? note : 'ETH tx from @kilnfi/sdk';
651659
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
652660

661+
const signature = fbTx?.signedMessages?.[0]?.signature;
662+
663+
if (!signature) {
664+
throw new Error('Fireblocks signature is missing');
665+
}
666+
653667
const preparedTx = await this.client.POST('/v1/eth/transaction/prepare', {
654668
body: {
655669
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,
659673
},
660674
});
661675

@@ -741,7 +755,11 @@ export class FireblocksService {
741755
const fbSigner = this.getSigner(integration);
742756
const fbNote = note ? note : 'TON tx from @kilnfi/sdk';
743757
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+
}
745763

746764
const preparedTx = await this.client.POST('/v1/ton/transaction/prepare', {
747765
body: {
@@ -783,7 +801,7 @@ export class FireblocksService {
783801
const fbSigner = this.getSigner(integration);
784802
const fbNote = note ? note : 'XTZ tx from @kilnfi/sdk';
785803
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
786-
const signature = fbTx.signedMessages?.[0].signature.fullSig;
804+
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
787805

788806
if (!signature) {
789807
throw new Error('Fireblocks signature is missing');
@@ -828,7 +846,7 @@ export class FireblocksService {
828846
const fbSigner = this.getSigner(integration);
829847
const fbNote = note ? note : 'NEAR tx from @kilnfi/sdk';
830848
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
831-
const signature = fbTx.signedMessages?.[0].signature.fullSig;
849+
const signature = fbTx.signedMessages?.[0]?.signature.fullSig;
832850

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

src/fireblocks_signer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from 'fireblocks-sdk';
1010

1111
import { formatEther, formatUnits } from 'viem';
12-
import type { components } from './openapi/schema';
12+
import type { components } from './openapi/schema.js';
1313

1414
export type AssetId =
1515
| 'SOL_TEST'
@@ -82,7 +82,7 @@ export class FireblocksSigner {
8282
* @param assetId fireblocks asset id
8383
* @param note optional fireblocks custom note
8484
*/
85-
public async sign(payloadToSign: object, assetId?: AssetId, note?: string): Promise<TransactionResponse> {
85+
public async sign(payloadToSign: object, assetId?: AssetId, note = ''): Promise<TransactionResponse> {
8686
try {
8787
const assetArgs = assetId
8888
? {
@@ -116,7 +116,7 @@ export class FireblocksSigner {
116116
public async signTypedMessage(
117117
eip712message: object,
118118
assetId: 'ETH' | 'ETH_TEST5' | 'ETH_TEST6',
119-
note?: string,
119+
note = '',
120120
): Promise<TransactionResponse> {
121121
try {
122122
const tx: TransactionArguments = {
@@ -160,7 +160,7 @@ export class FireblocksSigner {
160160
tx: components['schemas']['ETHUnsignedTx'] | components['schemas']['POLUnsignedTx'],
161161
destinationId: string,
162162
sendAmount = true,
163-
note?: string,
163+
note = '',
164164
): Promise<TransactionResponse> {
165165
try {
166166
const txArgs: TransactionArguments = {

src/kiln.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { paths } from './openapi/schema';
2-
export * from './validators';
3-
export * from './openapi/schema';
4-
export * from './utils';
1+
import type { paths } from './openapi/schema.js';
2+
export * from './validators.js';
3+
export * from './openapi/schema.js';
4+
export * from './utils.js';
55
import createClient, { type Client } from 'openapi-fetch';
6-
import { FireblocksService } from './fireblocks';
6+
import { FireblocksService } from './fireblocks.js';
77

88
type Config = {
99
baseUrl: string;

src/utils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { formatEther, formatUnits, parseUnits } from 'viem';
22

3-
// Convert Ethereum wei to ETH
3+
// Convert wei to ETH
44
export const weiToEth = (wei: bigint): string => {
55
return formatEther(BigInt(wei));
66
};
@@ -10,7 +10,7 @@ export const weiToPol = (wei: bigint): string => {
1010
return formatUnits(wei, 18);
1111
};
1212

13-
// Convert Solana lamports to SOL
13+
// Convert lamports to SOL
1414
export const lamportsToSol = (lamports: bigint): string => {
1515
return formatUnits(lamports, 9);
1616
};
@@ -30,44 +30,52 @@ export const lovelaceToAda = (lovelace: bigint): string => {
3030
return formatUnits(lovelace, 6);
3131
};
3232

33-
// Converts Near yocto to NEAR
33+
// Converts yocto to NEAR
3434
export const yoctoToNear = (yocto: bigint): string => {
3535
return formatUnits(yocto, 24);
3636
};
3737

38+
// Convert nanoTON to TON
3839
export const nanotonToTon = (nanoton: bigint): string => {
3940
return formatUnits(nanoton, 9);
4041
};
4142

43+
// Convert uZETA to ZETA
4244
export const uzetaToZeta = (uzeta: bigint): string => {
4345
return formatUnits(uzeta, 6);
4446
};
4547

48+
// Convert uINJ to INJ
4649
export const uinjToInj = (uinj: bigint): string => {
4750
return formatUnits(uinj, 6);
4851
};
4952

53+
// Convert aFET to FET
5054
export const afetToFet = (afet: bigint): string => {
5155
return formatUnits(afet, 18);
5256
};
5357

58+
// Convert uFET to FET
5459
export const ufetToFet = (ufet: bigint): string => {
5560
return formatUnits(ufet, 6);
5661
};
5762

58-
// Convert Tezos micro tez (mutez) to XTZ
63+
// Convert mutez to XTZ
5964
export const mutezToXtz = (mutez: bigint): string => {
6065
return formatUnits(mutez, 6);
6166
};
6267

68+
// Convert uDYDX to DYDX
6369
export const udydxToDydx = (udydx: bigint): string => {
6470
return formatUnits(udydx, 6);
6571
};
6672

73+
// Convert planck to DOT
6774
export const planckToDot = (planck: bigint): string => {
6875
return formatUnits(planck, 10);
6976
};
7077

78+
// Convert planck to KSM
7179
export const planckToKsm = (planck: bigint): string => {
7280
return formatUnits(planck, 12);
7381
};
@@ -77,6 +85,7 @@ export const uatomToAtom = (uatom: bigint): string => {
7785
return formatUnits(uatom, 6);
7886
};
7987

88+
// Convert u{Cosmos chain token: ATOM, OSMO, etc...} to {Cosmos chain token: ATOM, OSMO, etc...}
8089
export const uunitToUnit = (uunit: bigint): string => {
8190
return formatUnits(uunit, 6);
8291
};

tsconfig.base.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
// This tsconfig file contains the shared config for the build (tsconfig.build.json) and type checking (tsconfig.json) config.
3+
"include": [],
4+
"compilerOptions": {
5+
// Type checking
6+
"strict": true,
7+
"useDefineForClassFields": true, // Not enabled by default in `strict` mode unless we bump `target` to ES2022.
8+
"noFallthroughCasesInSwitch": true, // Not enabled by default in `strict` mode.
9+
"noImplicitReturns": true, // Not enabled by default in `strict` mode.
10+
"noImplicitOverride": true, // Not enabled by default in `strict` mode.
11+
"noUnusedLocals": true, // Not enabled by default in `strict` mode.
12+
"noUnusedParameters": true, // Not enabled by default in `strict` mode.
13+
"exactOptionalPropertyTypes": true,
14+
"noUncheckedIndexedAccess": true,
15+
16+
// JavaScript support
17+
"allowJs": false,
18+
"checkJs": false,
19+
20+
// Interop constraints
21+
"esModuleInterop": false,
22+
"allowSyntheticDefaultImports": false,
23+
"forceConsistentCasingInFileNames": true,
24+
"verbatimModuleSyntax": true,
25+
26+
// Language and environment
27+
"moduleResolution": "NodeNext",
28+
"module": "NodeNext",
29+
"target": "ES2021",
30+
"lib": ["ES2022", "DOM"],
31+
32+
// Skip type checking for node modules
33+
"skipLibCheck": true
34+
}
35+
}

tsconfig.build.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// This file is used to compile the for cjs and esm (see package.json build scripts). It should exclude all test files.
3+
"extends": "./tsconfig.base.json",
4+
"include": ["src"],
5+
"compilerOptions": {
6+
"moduleResolution": "node",
7+
"sourceMap": true,
8+
"rootDir": "./src"
9+
}
10+
}

0 commit comments

Comments
 (0)