Skip to content

Commit fcec99e

Browse files
Update OpenAPI schema (#241)
* Update OpenAPI schema * add sei support * bump version --------- Co-authored-by: Kiln Bot <[email protected]> Co-authored-by: menefrego15 <[email protected]>
1 parent 2a3e984 commit fcec99e

File tree

7 files changed

+3112
-2270
lines changed

7 files changed

+3112
-2270
lines changed

examples/sei.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import type { FireblocksIntegration } from '../src/fireblocks.ts';
2+
import { KILN_VALIDATORS, Kiln, seiToUsei } from '../src/kiln.ts';
3+
import { loadEnv } from './env.ts';
4+
5+
const { kilnApiKey, kilnAccountId, kilnApiUrl, fireblocksApiKey, fireblocksApiSecret, fireblocksVaultId } =
6+
await loadEnv();
7+
8+
const k = new Kiln({
9+
baseUrl: kilnApiUrl,
10+
apiToken: kilnApiKey,
11+
});
12+
13+
const vault: FireblocksIntegration = {
14+
config: {
15+
apiKey: fireblocksApiKey,
16+
secretKey: fireblocksApiSecret,
17+
basePath: 'https://api.fireblocks.io/v1',
18+
},
19+
vaultId: fireblocksVaultId,
20+
};
21+
22+
//
23+
// Get the pubkey from Fireblocks
24+
//
25+
const fireblocksPubkey = (
26+
await k.fireblocks.getSdk(vault).vaults.getPublicKeyInfo({
27+
algorithm: 'MPC_ECDSA_SECP256K1',
28+
derivationPath: JSON.stringify([44, 118, Number(vault.vaultId), 0, 0]),
29+
compressed: true,
30+
})
31+
).data.publicKey;
32+
if (!fireblocksPubkey) {
33+
console.log('Failed to get pubkey');
34+
process.exit(0);
35+
}
36+
37+
//
38+
// Craft the transaction
39+
//
40+
console.log('Crafting transaction...');
41+
const txRequest = await k.client.POST('/sei/transaction/stake', {
42+
body: {
43+
account_id: kilnAccountId,
44+
pubkey: fireblocksPubkey,
45+
validator: KILN_VALIDATORS.SEI.mainnet.KILN,
46+
amount_usei: seiToUsei('0.01').toString(),
47+
restake_rewards: false,
48+
},
49+
});
50+
if (txRequest.error) {
51+
console.log('Failed to craft transaction:', txRequest);
52+
process.exit(1);
53+
} else {
54+
console.log('Crafted transaction:', txRequest.data);
55+
}
56+
console.log('\n\n\n');
57+
58+
//
59+
// Sign the transaction
60+
//
61+
console.log('Signing transaction...');
62+
const signRequest = await (async () => {
63+
try {
64+
return await k.fireblocks.signSeiTx(vault, txRequest.data.data);
65+
} catch (err) {
66+
console.log('Failed to sign transaction:', err);
67+
process.exit(1);
68+
}
69+
})();
70+
console.log('Signed transaction:', signRequest);
71+
console.log('\n\n\n');
72+
73+
//
74+
// Broadcast the transaction
75+
//
76+
console.log('Broadcasting transaction...');
77+
const broadcastedRequest = await k.client.POST('/sei/transaction/broadcast', {
78+
body: {
79+
tx_serialized: signRequest.signed_tx.data.signed_tx_serialized,
80+
},
81+
});
82+
if (broadcastedRequest.error) {
83+
console.log('Failed to broadcast transaction:', broadcastedRequest);
84+
process.exit(1);
85+
} else {
86+
console.log('Broadcasted transaction:', broadcastedRequest.data);
87+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kilnfi/sdk",
3-
"version": "4.2.13",
3+
"version": "4.2.14",
44
"autor": "Kiln <[email protected]> (https://kiln.fi)",
55
"license": "BUSL-1.1",
66
"description": "JavaScript sdk for Kiln API",

src/fireblocks.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,4 +1216,59 @@ export class FireblocksService {
12161216
fireblocks_tx: fbTx,
12171217
};
12181218
}
1219+
1220+
/**
1221+
* Sign a SEI transaction on Fireblocks
1222+
*/
1223+
async signSeiTx(
1224+
integration: FireblocksIntegration,
1225+
tx: components['schemas']['SEIUnsignedTx'] | components['schemas']['SEIStakeUnsignedTx'],
1226+
note?: string,
1227+
): Promise<{
1228+
signed_tx: { data: components['schemas']['SEISignedTx'] };
1229+
fireblocks_tx: TransactionResponse;
1230+
}> {
1231+
const payload = {
1232+
rawMessageData: {
1233+
messages: [
1234+
{
1235+
content: tx.unsigned_tx_hash,
1236+
derivationPath: [44, 118, Number(integration.vaultId), 0, 0],
1237+
preHash: {
1238+
content: tx.unsigned_tx_serialized,
1239+
hashAlgorithm: 'SHA256',
1240+
},
1241+
},
1242+
],
1243+
algorithm: SignedMessageAlgorithmEnum.EcdsaSecp256K1,
1244+
},
1245+
};
1246+
1247+
const fbSigner = this.getSigner(integration);
1248+
const fbNote = note ? note : 'SEI tx from @kilnfi/sdk';
1249+
const fbTx = await fbSigner.sign(payload, undefined, fbNote);
1250+
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
1251+
1252+
if (!signature) {
1253+
throw new Error(ERRORS.MISSING_SIGNATURE);
1254+
}
1255+
1256+
const preparedTx = await this.client.POST('/sei/transaction/prepare', {
1257+
body: {
1258+
pubkey: tx.pubkey,
1259+
tx_body: tx.tx_body,
1260+
tx_auth_info: tx.tx_auth_info,
1261+
signature: signature,
1262+
},
1263+
});
1264+
1265+
if (preparedTx.error) {
1266+
throw new Error(ERRORS.FAILED_TO_PREPARE);
1267+
}
1268+
1269+
return {
1270+
signed_tx: preparedTx.data,
1271+
fireblocks_tx: fbTx,
1272+
};
1273+
}
12191274
}

src/fireblocks_signer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export type FireblocksAssetId =
3535
| 'TON'
3636
| 'KAVA_KAVA'
3737
| 'TRX'
38-
| 'BTC';
38+
| 'BTC'
39+
| 'SEI';
3940

4041
export class FireblocksSigner {
4142
constructor(

0 commit comments

Comments
 (0)