diff --git a/examples/kava.ts b/examples/kava.ts new file mode 100644 index 0000000..a1fcdb9 --- /dev/null +++ b/examples/kava.ts @@ -0,0 +1,48 @@ +import { kavaToUkava, Kiln } from "../src/kiln"; +import fs from "node:fs"; +import 'dotenv/config' +import type { FireblocksIntegration } from "../src/fireblocks.ts"; + + +const apiSecret = fs.readFileSync(`${__dirname}/fireblocks_secret_prod.key`, 'utf8'); + +const k = new Kiln({ + baseUrl: process.env.KILN_API_URL as string, + apiToken: process.env.KILN_API_KEY as string, +}); + +const vault: FireblocksIntegration = { + provider: 'fireblocks', + fireblocksApiKey: process.env.FIREBLOCKS_API_KEY as string, + fireblocksSecretKey: apiSecret, + vaultId: 37 +}; + +try { + console.log('crafting...'); + const tx = await k.client.POST( + '/v1/kava/transaction/stake', + { + body: { + account_id: process.env.KILN_ACCOUNT_ID as string, + pubkey: '0233335b6c68a85e01b85055d0e8c2fcef42fed977898422ef3a5f6baf9a9a413e', + validator: 'kavavaloper1djqecw6nn5tydxq0shan7srv8j65clsf79myt8', + amount_ukava: kavaToUkava('0.01').toString(), + } + } + ); + console.log('signing...'); + if(!tx.data?.data) throw new Error('No data in response'); + const signResponse = await k.fireblocks.signKavaTx(vault, tx.data.data); + console.log('broadcasting...'); + if(!signResponse.signed_tx?.data?.signed_tx_serialized) throw new Error('No signed_tx in response'); + const broadcastedTx = await k.client.POST("/v1/kava/transaction/broadcast", { + body: { + tx_serialized: signResponse.signed_tx.data.signed_tx_serialized, + } + }); + console.log(broadcastedTx); + +} catch (err) { + console.log(err); +} \ No newline at end of file diff --git a/package.json b/package.json index 78faaca..d76d1da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kilnfi/sdk", - "version": "3.1.15", + "version": "3.1.16", "autor": "Kiln (https://kiln.fi)", "license": "BUSL-1.1", "description": "JavaScript sdk for Kiln API", diff --git a/src/fireblocks.ts b/src/fireblocks.ts index f2c29ba..ee8663c 100644 --- a/src/fireblocks.ts +++ b/src/fireblocks.ts @@ -414,18 +414,20 @@ export class FireblocksService { messages: [ { content: tx.unsigned_tx_hash, + derivationPath: [44, 459, integration.vaultId, 0, 0], preHash: { content: tx.unsigned_tx_serialized, hashAlgorithm: 'SHA256', }, }, ], + algorithm: SigningAlgorithm.MPC_ECDSA_SECP256K1, }, }; const fbSigner = this.getSigner(integration); const fbNote = note ? note : 'KAVA tx from @kilnfi/sdk'; - const fbTx = await fbSigner.sign(payload, 'KAVA_KAVA', fbNote); + const fbTx = await fbSigner.sign(payload, undefined, fbNote); const signature = fbTx.signedMessages?.[0]?.signature.fullSig; if (!signature) { diff --git a/src/utils.ts b/src/utils.ts index 2e82076..5a79741 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -63,6 +63,13 @@ export const tonToNanoton = (ton: string): bigint => { return parseUnits(ton, 9); }; +/** + * Convert KAVA to uKAVA + */ +export const kavaToUkava = (kava: string): bigint => { + return parseUnits(kava, 6); +}; + /** * Convert uZETA to ZETA */