-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add cronos sign fx and example * bump v4.1.4
- Loading branch information
1 parent
4abda2a
commit 54a0c99
Showing
5 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Kiln, KILN_VALIDATORS, croToBasecro } from '../src/kiln.ts'; | ||
import type { FireblocksIntegration } from '../src/fireblocks.ts'; | ||
import { loadEnv } from './env.ts'; | ||
|
||
const { kilnApiKey, kilnAccountId, kilnApiUrl, fireblocksApiKey, fireblocksApiSecret, fireblocksVaultId } = | ||
await loadEnv(); | ||
|
||
const k = new Kiln({ | ||
baseUrl: kilnApiUrl, | ||
apiToken: kilnApiKey, | ||
}); | ||
|
||
const vault: FireblocksIntegration = { | ||
config: { | ||
apiKey: fireblocksApiKey, | ||
secretKey: fireblocksApiSecret, | ||
basePath: 'https://api.fireblocks.io/v1', | ||
}, | ||
vaultId: fireblocksVaultId, | ||
}; | ||
|
||
// | ||
// Get the pubkey from Fireblocks | ||
// | ||
const fireblocksPubkey = ( | ||
await k.fireblocks.getSdk(vault).vaults.getPublicKeyInfo({ | ||
algorithm: 'MPC_ECDSA_SECP256K1', | ||
derivationPath: JSON.stringify([44, 394, Number(vault.vaultId), 0, 0]), | ||
compressed: true, | ||
}) | ||
).data.publicKey; | ||
if (!fireblocksPubkey) { | ||
console.log('Failed to get pubkey'); | ||
process.exit(0); | ||
} | ||
|
||
// | ||
// Craft the transaction | ||
// | ||
console.log('Crafting transaction...'); | ||
const txRequest = await k.client.POST('/cro/transaction/stake', { | ||
body: { | ||
account_id: kilnAccountId, | ||
pubkey: fireblocksPubkey, | ||
validator: KILN_VALIDATORS.CRO.mainnet.KILN, | ||
amount_basecro: croToBasecro('0.01').toString(), | ||
restake_rewards: false, | ||
}, | ||
}); | ||
if (txRequest.error) { | ||
console.log('Failed to craft transaction:', txRequest); | ||
process.exit(1); | ||
} else { | ||
console.log('Crafted transaction:', txRequest.data); | ||
} | ||
console.log('\n\n\n'); | ||
|
||
// | ||
// Sign the transaction | ||
// | ||
console.log('Signing transaction...'); | ||
const signRequest = await (async () => { | ||
try { | ||
return await k.fireblocks.signCroTx(vault, txRequest.data.data); | ||
} catch (err) { | ||
console.log('Failed to sign transaction:', err); | ||
process.exit(1); | ||
} | ||
})(); | ||
console.log('Signed transaction:', signRequest); | ||
console.log('\n\n\n'); | ||
|
||
// | ||
// Broadcast the transaction | ||
// | ||
console.log('Broadcasting transaction...'); | ||
const broadcastedRequest = await k.client.POST('/cro/transaction/broadcast', { | ||
body: { | ||
tx_serialized: signRequest.signed_tx.data.signed_tx_serialized, | ||
}, | ||
}); | ||
if (broadcastedRequest.error) { | ||
console.log('Failed to broadcast transaction:', broadcastedRequest); | ||
process.exit(1); | ||
} else { | ||
console.log('Broadcasted transaction:', broadcastedRequest.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@kilnfi/sdk", | ||
"version": "4.1.3", | ||
"version": "4.1.4", | ||
"autor": "Kiln <[email protected]> (https://kiln.fi)", | ||
"license": "BUSL-1.1", | ||
"description": "JavaScript sdk for Kiln API", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters