utils
class of the K2 SDK.
add0x function
This function can be used to append0x
towards the start of a string to convert it into a hex string accepted by the contracts. If the input string already contains the 0x
, the function will return the string as is.
Input Parameters
data: string which needs to be appended by0x
Using add0x function
Return Parameter
Returns hex stringremove0x function
This function removes0x
from the beginning of a string. If the input string doesn’t contain 0x
, it will return the string as is.
Input Parameters
data: string to remove0x
from
Using remove0x function
Return Parameter
Returns string without0x
in the beginning.
generateLivenessReport function
This function can be used to generate a liveness reports of the software being run.Input Parameters
middlewareAPI: API endpoint of the middlewareUsing generateLivenessReport function
Return Parameter
Returns a liveness report. Here’s a sample liveness report:getMiddlewareInfo function
This function can be used to get the info from the middleware endpoint.Input Parameters
middlewareAPI: API endpoint of the middlewareUsing getMiddlewareInfo function
Return Parameter
The function returns info related to the middleware API. Here’s an example of the info:verifyReport function
Once the liveness or the corruption report has been generated, it needs to be verified before submitting it to the reporter registry. To verify the report,verifyReport
function should be used.
Input Parameters
middlewareAPI: API endpoint of the middlewarereport: Liveness or the corruption report returned by the respective function
Using verifyReport function
Return Parameter
The function returns a verified report which contains the liveness report along with a signature valid for 20 minutes. Here’s how a verified report looks like:verifyEffectiveBalance function
This function can be used to batch verify effective balance of a list of BLS public keys.Input Parameters
blsPublicKeys: List of BLS public keys in string formateffectiveBalances: List of effective balance in string corresponding to each BLS public key
Using verifyEffectiveBalance function
Return Parameter
The function returns a list of verified effective balance report after it has been successfully verified and error otherwise.readUsingMulticall function
Allows to read batch values from a contract in a single RPC call.Input Parameters
targetContract: Address of the target contract in string formatallowFailure: Boolean. Set to
true
to throw error if any one value is rejected by the contractcalldata: List of calldata in string
Using readUsingMulticall function
Return Parameter
Returns a list of response for each call data in the format:getEffectiveBalance function
Get effective balance of a BLS public key from the consensus layer.Input Parameters
beaconNodeUrl: Beacon node URL stringblsPublicKey: BLS public key in string format to get effective balance of
Using getEffectiveBalance function
Return Parameter
Effective balance in numbersgenerateCorruptionReport function
Generate corruption report from the data received from middleware API endpoint.Input Parameters
middlewareAPI: API endpoint of the middlewareeventData: event data of the format CorruptionEventDataT
message: string message which needs to be mentioned in the report. Default value:
''
debtorOverride: optional debtor address. Can be left
null
for the function to fetch debtor address from the middlewareAPI
Using generateCorruptionReport function
Return Parameter
Returns corruption report of the format:claimEffectiveBalance function
Claim effective balance for all the BLS public keys delegated by the user.Input Parameters
beaconNodeUrl: Beacon node URL in stringuserAddress: user address in string