import CardanoWasm , { StakeCredential } from 'cardano-serialization-lib' ; import { Logger } from 'fastify' ; import { ErrorFactory } from '../errors' ; import { hexStringToBuffer } from '../formatters' ; import { isKeyValid } from '../validations' ; param logger param publicKey export const getPublicKey = ( logger , publicKey ? ) => { if ( ! publicKey || ! publicKey . hex_bytes ) { logger . error ( '[getPublicKey] Staking key not provided' ) ; throw ErrorFactory . missingStakingKeyError ( ) ; } if ( ! isKeyValid ( publicKey . hex_bytes , publicKey . curve_type ) ) { logger . info ( '[getPublicKey] Staking key has an invalid format' ) ; throw ErrorFactory . invalidStakingKeyFormat ( ) ; } const stakingKeyBuffer = hexStringToBuffer ( publicKey . hex_bytes ) ; return CardanoWasm . PublicKey . from_bytes ( stakingKeyBuffer ) ; } ; param logger param staking_credential export const getStakingCredentialFromHex = ( logger , staking_credential ? ) : StakeCredential => { const stakingKey = getPublicKey ( logger , staking_credential ) ; return StakeCredential . from_keyhash ( stakingKey . hash ( ) ) ; } ;