From 72454323908b25dc11f0c577cc5d4700d782774f Mon Sep 17 00:00:00 2001 From: Arno Simon Date: Thu, 14 Nov 2024 16:40:57 +0100 Subject: [PATCH 1/2] fix signKavaTx and add kava example --- examples/kava.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- src/fireblocks.ts | 4 +++- src/utils.ts | 7 +++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 examples/kava.ts 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..931056c 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 */ From 46aa31b868812cb3c43b94c9b099e5e7eb8e077f Mon Sep 17 00:00:00 2001 From: Arno Simon Date: Thu, 14 Nov 2024 16:42:39 +0100 Subject: [PATCH 2/2] format --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 931056c..5a79741 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -68,7 +68,7 @@ export const tonToNanoton = (ton: string): bigint => { */ export const kavaToUkava = (kava: string): bigint => { return parseUnits(kava, 6); -} +}; /** * Convert uZETA to ZETA