UNPKG

@lodestar/api

Version:

A Typescript REST client for the Ethereum Consensus API

348 lines • 14.2 kB
import { ContainerType } from "@chainsafe/ssz"; import { ssz, stringType } from "@lodestar/types"; import { EmptyMetaCodec, EmptyRequestCodec, EmptyResponseCodec, JsonOnlyReq, JsonOnlyResponseCodec, } from "../utils/codecs.js"; import { Schema } from "../utils/index.js"; import { WireFormat } from "../utils/wireFormat.js"; export var ImportStatus; (function (ImportStatus) { /** Keystore successfully decrypted and imported to keymanager permanent storage */ ImportStatus["imported"] = "imported"; /** Keystore's pubkey is already known to the keymanager */ ImportStatus["duplicate"] = "duplicate"; /** Any other status different to the above: decrypting error, I/O errors, etc. */ ImportStatus["error"] = "error"; })(ImportStatus || (ImportStatus = {})); export var DeletionStatus; (function (DeletionStatus) { /** key was active and removed */ DeletionStatus["deleted"] = "deleted"; /** slashing protection data returned but key was not active */ DeletionStatus["not_active"] = "not_active"; /** key was not found to be removed, and no slashing data can be returned */ DeletionStatus["not_found"] = "not_found"; /** unexpected condition meant the key could not be removed (the key was actually found, but we couldn't stop using it) - this would be a sign that making it active elsewhere would almost certainly cause you headaches / slashing conditions etc. */ DeletionStatus["error"] = "error"; })(DeletionStatus || (DeletionStatus = {})); export var ImportRemoteKeyStatus; (function (ImportRemoteKeyStatus) { /** Remote key successfully imported to validator client permanent storage */ ImportRemoteKeyStatus["imported"] = "imported"; /** Remote key's pubkey is already known to the validator client */ ImportRemoteKeyStatus["duplicate"] = "duplicate"; /** Any other status different to the above: I/O errors, etc. */ ImportRemoteKeyStatus["error"] = "error"; })(ImportRemoteKeyStatus || (ImportRemoteKeyStatus = {})); export var DeleteRemoteKeyStatus; (function (DeleteRemoteKeyStatus) { /** key was active and removed */ DeleteRemoteKeyStatus["deleted"] = "deleted"; /** key was not found to be removed */ DeleteRemoteKeyStatus["not_found"] = "not_found"; /** * unexpected condition meant the key could not be removed (the key was actually found, * but we couldn't stop using it) - this would be a sign that making it active elsewhere would * almost certainly cause you headaches / slashing conditions etc. */ DeleteRemoteKeyStatus["error"] = "error"; })(DeleteRemoteKeyStatus || (DeleteRemoteKeyStatus = {})); export const FeeRecipientDataType = new ContainerType({ pubkey: stringType, ethaddress: stringType, }, { jsonCase: "eth2" }); export const GraffitiDataType = new ContainerType({ pubkey: stringType, graffiti: stringType, }, { jsonCase: "eth2" }); export const GasLimitDataType = new ContainerType({ pubkey: stringType, gasLimit: ssz.UintNum64, }, { jsonCase: "eth2" }); export const BuilderBoostFactorDataType = new ContainerType({ pubkey: stringType, builderBoostFactor: ssz.UintBn64, }, { jsonCase: "eth2" }); export function getDefinitions(_config) { return { listKeys: { url: "/eth/v1/keystores", method: "GET", req: EmptyRequestCodec, resp: JsonOnlyResponseCodec, }, importKeystores: { url: "/eth/v1/keystores", method: "POST", req: JsonOnlyReq({ writeReqJson: ({ keystores, passwords, slashingProtection }) => ({ body: { keystores, passwords, slashing_protection: slashingProtection }, }), parseReqJson: ({ body: { keystores, passwords, slashing_protection } }) => ({ keystores, passwords, slashingProtection: slashing_protection, }), schema: { body: Schema.Object }, }), resp: JsonOnlyResponseCodec, }, deleteKeys: { url: "/eth/v1/keystores", method: "DELETE", req: JsonOnlyReq({ writeReqJson: ({ pubkeys }) => ({ body: { pubkeys } }), parseReqJson: ({ body: { pubkeys } }) => ({ pubkeys }), schema: { body: Schema.Object }, }), resp: { onlySupport: WireFormat.json, data: JsonOnlyResponseCodec.data, meta: EmptyMetaCodec, transform: { toResponse: (data) => { const { statuses, slashing_protection } = data; return { data: statuses, slashing_protection }; }, fromResponse: (resp) => { const { data, slashing_protection } = resp; return { data: { statuses: data, slashingProtection: slashing_protection } }; }, }, }, }, listRemoteKeys: { url: "/eth/v1/remotekeys", method: "GET", req: EmptyRequestCodec, resp: JsonOnlyResponseCodec, }, importRemoteKeys: { url: "/eth/v1/remotekeys", method: "POST", req: JsonOnlyReq({ writeReqJson: ({ remoteSigners }) => ({ body: { remote_keys: remoteSigners } }), parseReqJson: ({ body: { remote_keys } }) => ({ remoteSigners: remote_keys }), schema: { body: Schema.Object }, }), resp: JsonOnlyResponseCodec, }, deleteRemoteKeys: { url: "/eth/v1/remotekeys", method: "DELETE", req: JsonOnlyReq({ writeReqJson: ({ pubkeys }) => ({ body: { pubkeys } }), parseReqJson: ({ body: { pubkeys } }) => ({ pubkeys }), schema: { body: Schema.Object }, }), resp: JsonOnlyResponseCodec, }, listFeeRecipient: { url: "/eth/v1/validator/{pubkey}/feerecipient", method: "GET", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: { onlySupport: WireFormat.json, data: FeeRecipientDataType, meta: EmptyMetaCodec, }, }, setFeeRecipient: { url: "/eth/v1/validator/{pubkey}/feerecipient", method: "POST", req: JsonOnlyReq({ writeReqJson: ({ pubkey, ethaddress }) => ({ params: { pubkey }, body: { ethaddress } }), parseReqJson: ({ params: { pubkey }, body: { ethaddress } }) => ({ pubkey, ethaddress }), schema: { params: { pubkey: Schema.StringRequired }, body: Schema.Object, }, }), resp: EmptyResponseCodec, }, deleteFeeRecipient: { url: "/eth/v1/validator/{pubkey}/feerecipient", method: "DELETE", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: EmptyResponseCodec, }, getGraffiti: { url: "/eth/v1/validator/{pubkey}/graffiti", method: "GET", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: { onlySupport: WireFormat.json, data: GraffitiDataType, meta: EmptyMetaCodec, }, }, setGraffiti: { url: "/eth/v1/validator/{pubkey}/graffiti", method: "POST", req: JsonOnlyReq({ writeReqJson: ({ pubkey, graffiti }) => ({ params: { pubkey }, body: { graffiti } }), parseReqJson: ({ params: { pubkey }, body: { graffiti } }) => ({ pubkey, graffiti }), schema: { params: { pubkey: Schema.StringRequired }, body: Schema.Object, }, }), resp: EmptyResponseCodec, }, deleteGraffiti: { url: "/eth/v1/validator/{pubkey}/graffiti", method: "DELETE", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: EmptyResponseCodec, }, getGasLimit: { url: "/eth/v1/validator/{pubkey}/gas_limit", method: "GET", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: { onlySupport: WireFormat.json, data: GasLimitDataType, meta: EmptyMetaCodec, }, }, setGasLimit: { url: "/eth/v1/validator/{pubkey}/gas_limit", method: "POST", req: JsonOnlyReq({ writeReqJson: ({ pubkey, gasLimit }) => ({ params: { pubkey }, body: { gas_limit: gasLimit.toString(10) } }), parseReqJson: ({ params: { pubkey }, body: { gas_limit } }) => ({ pubkey, gasLimit: parseGasLimit(gas_limit) }), schema: { params: { pubkey: Schema.StringRequired }, body: Schema.Object, }, }), resp: EmptyResponseCodec, }, deleteGasLimit: { url: "/eth/v1/validator/{pubkey}/gas_limit", method: "DELETE", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: EmptyResponseCodec, }, getBuilderBoostFactor: { url: "/eth/v1/validator/{pubkey}/builder_boost_factor", method: "GET", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: { onlySupport: WireFormat.json, data: BuilderBoostFactorDataType, meta: EmptyMetaCodec, }, }, setBuilderBoostFactor: { url: "/eth/v1/validator/{pubkey}/builder_boost_factor", method: "POST", req: JsonOnlyReq({ writeReqJson: ({ pubkey, builderBoostFactor }) => ({ params: { pubkey }, body: { builder_boost_factor: builderBoostFactor.toString(10) }, }), parseReqJson: ({ params: { pubkey }, body: { builder_boost_factor } }) => ({ pubkey, builderBoostFactor: BigInt(builder_boost_factor), }), schema: { params: { pubkey: Schema.StringRequired }, body: Schema.Object, }, }), resp: EmptyResponseCodec, }, deleteBuilderBoostFactor: { url: "/eth/v1/validator/{pubkey}/builder_boost_factor", method: "DELETE", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: EmptyResponseCodec, }, getProposerConfig: { url: "/eth/v0/validator/{pubkey}/proposer_config", method: "GET", req: { writeReq: ({ pubkey }) => ({ params: { pubkey } }), parseReq: ({ params: { pubkey } }) => ({ pubkey }), schema: { params: { pubkey: Schema.StringRequired }, }, }, resp: JsonOnlyResponseCodec, }, signVoluntaryExit: { url: "/eth/v1/validator/{pubkey}/voluntary_exit", method: "POST", req: { writeReq: ({ pubkey, epoch }) => ({ params: { pubkey }, query: { epoch } }), parseReq: ({ params: { pubkey }, query: { epoch } }) => ({ pubkey, epoch }), schema: { params: { pubkey: Schema.StringRequired }, query: { epoch: Schema.Uint }, }, }, resp: { data: ssz.phase0.SignedVoluntaryExit, meta: EmptyMetaCodec, }, }, }; } function parseGasLimit(gasLimitInput) { if ((typeof gasLimitInput !== "string" && typeof gasLimitInput !== "number") || `${gasLimitInput}`.trim() === "") { throw Error("Not valid Gas Limit"); } const gasLimit = Number(gasLimitInput); if (Number.isNaN(gasLimit) || gasLimit === 0) { throw Error(`Gas Limit is not valid gasLimit=${gasLimit}`); } return gasLimit; } //# sourceMappingURL=routes.js.map