Search in sources :

Example 6 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project web3signer by ConsenSys.

the class Eth2RequestUtils method createAggregateAndProof.

private static Eth2SigningRequestBody createAggregateAndProof() {
    final ForkInfo forkInfo = forkInfo();
    final Bytes sszBytes = Bytes.of(0, 0, 1, 1);
    final Attestation attestation = new Attestation(sszBytes, new AttestationData(UInt64.ZERO, UInt64.ZERO, Bytes32.fromHexString("0x100814c335d0ced5014cfa9d2e375e6d9b4e197381f8ce8af0473200fdc917fd"), new Checkpoint(UInt64.ZERO, Bytes32.ZERO), new Checkpoint(UInt64.ZERO, Bytes32.fromHexString("0x100814c335d0ced5014cfa9d2e375e6d9b4e197381f8ce8af0473200fdc917fd"))), BLSSignature.fromHexString("0xa627242e4a5853708f4ebf923960fb8192f93f2233cd347e05239d86dd9fb66b721ceec1baeae6647f498c9126074f1101a87854d674b6eebc220fd8c3d8405bdfd8e286b707975d9e00a56ec6cbbf762f23607d490f0bbb16c3e0e483d51875"));
    final BLSSignature selectionProof = BLSSignature.fromHexString("0xa63f73a03f1f42b1fd0a988b614d511eb346d0a91c809694ef76df5ae021f0f144d64e612d735bc8820950cf6f7f84cd0ae194bfe3d4242fe79688f83462e3f69d9d33de71aab0721b7dab9d6960875e5fdfd26b171a75fb51af822043820c47");
    final AggregateAndProof aggregateAndProof = new AggregateAndProof(UInt64.ONE, attestation, selectionProof);
    final Bytes signingRoot = signingRootUtil.signingRootForSignAggregateAndProof(aggregateAndProof.asInternalAggregateAndProof(spec), forkInfo.asInternalForkInfo());
    return new Eth2SigningRequestBody(ArtifactType.AGGREGATE_AND_PROOF, signingRoot, forkInfo, null, null, null, null, aggregateAndProof, null, null, null, null, null, null);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) AttestationData(tech.pegasys.teku.api.schema.AttestationData) Checkpoint(tech.pegasys.teku.api.schema.Checkpoint) ForkInfo(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.ForkInfo) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Attestation(tech.pegasys.teku.api.schema.Attestation) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) AggregateAndProof(tech.pegasys.teku.api.schema.AggregateAndProof)

Example 7 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project teku by ConsenSys.

the class GetNewBlock method handle.

@OpenApi(path = OAPI_ROUTE, deprecated = true, method = HttpMethod.GET, summary = "Produce unsigned block", tags = { TAG_VALIDATOR, TAG_VALIDATOR_REQUIRED }, description = "Requests a beacon node to produce a valid block, which can then be signed by a validator.\n\n" + "__NOTE__: deprecated, switch to using `/eth/v2/validator/blocks/{slot}` for multiple milestone support.", pathParams = { @OpenApiParam(name = SLOT, description = "The slot for which the block should be proposed.") }, queryParams = { @OpenApiParam(name = RANDAO_REVEAL, description = "`BLSSignature Hex` BLS12-381 signature for the current epoch.", required = true), @OpenApiParam(name = GRAFFITI, description = "`Bytes32 Hex` Graffiti.") }, responses = { @OpenApiResponse(status = RES_OK, content = @OpenApiContent(from = GetNewBlockResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied"), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) })
@Override
public void handle(final Context ctx) throws Exception {
    try {
        final Map<String, List<String>> queryParamMap = ctx.queryParamMap();
        final Map<String, String> pathParamMap = ctx.pathParamMap();
        final UInt64 slot = UInt64.valueOf(pathParamMap.get(SLOT));
        final BLSSignature randao = getParameterValueAsBLSSignature(queryParamMap, RANDAO_REVEAL);
        final Optional<Bytes32> graffiti = getOptionalParameterValueAsBytes32(queryParamMap, GRAFFITI);
        ctx.future(provider.getUnsignedBeaconBlockAtSlot(slot, randao, graffiti).thenApplyChecked(maybeBlock -> {
            if (maybeBlock.isEmpty()) {
                throw new ChainDataUnavailableException();
            }
            return produceResultString(maybeBlock.get());
        }).exceptionallyCompose(error -> handleError(ctx, error)));
    } catch (final IllegalArgumentException e) {
        ctx.status(SC_BAD_REQUEST);
        ctx.json(jsonProvider.objectToJSON(new BadRequest(e.getMessage())));
    }
}
Also used : AbstractHandler(tech.pegasys.teku.beaconrestapi.handlers.AbstractHandler) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) RES_SERVICE_UNAVAILABLE(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_SERVICE_UNAVAILABLE) OpenApiContent(io.javalin.plugin.openapi.annotations.OpenApiContent) RANDAO_REVEAL(tech.pegasys.teku.infrastructure.http.RestApiConstants.RANDAO_REVEAL) SERVICE_UNAVAILABLE(tech.pegasys.teku.infrastructure.http.RestApiConstants.SERVICE_UNAVAILABLE) SLOT(tech.pegasys.teku.infrastructure.http.RestApiConstants.SLOT) SingleQueryParameterUtils.getParameterValueAsBytes32(tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils.getParameterValueAsBytes32) ValidatorDataProvider(tech.pegasys.teku.api.ValidatorDataProvider) GRAFFITI(tech.pegasys.teku.infrastructure.http.RestApiConstants.GRAFFITI) RES_INTERNAL_ERROR(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_INTERNAL_ERROR) TAG_VALIDATOR(tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_VALIDATOR) RES_BAD_REQUEST(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_BAD_REQUEST) Context(io.javalin.http.Context) OpenApiResponse(io.javalin.plugin.openapi.annotations.OpenApiResponse) Map(java.util.Map) JsonProvider(tech.pegasys.teku.provider.JsonProvider) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ChainDataUnavailableException(tech.pegasys.teku.storage.client.ChainDataUnavailableException) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) HttpMethod(io.javalin.plugin.openapi.annotations.HttpMethod) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) BadRequest(tech.pegasys.teku.beaconrestapi.schema.BadRequest) TAG_VALIDATOR_REQUIRED(tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_VALIDATOR_REQUIRED) Throwables(com.google.common.base.Throwables) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) GetNewBlockResponse(tech.pegasys.teku.api.response.v1.validator.GetNewBlockResponse) Handler(io.javalin.http.Handler) List(java.util.List) OpenApiParam(io.javalin.plugin.openapi.annotations.OpenApiParam) SingleQueryParameterUtils.getParameterValueAsBLSSignature(tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils.getParameterValueAsBLSSignature) RES_OK(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_OK) Optional(java.util.Optional) SC_BAD_REQUEST(javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi) DataProvider(tech.pegasys.teku.api.DataProvider) BadRequest(tech.pegasys.teku.beaconrestapi.schema.BadRequest) ChainDataUnavailableException(tech.pegasys.teku.storage.client.ChainDataUnavailableException) List(java.util.List) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SingleQueryParameterUtils.getParameterValueAsBytes32(tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils.getParameterValueAsBytes32) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) SingleQueryParameterUtils.getParameterValueAsBLSSignature(tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils.getParameterValueAsBLSSignature) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Example 8 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project teku by ConsenSys.

the class PostSyncCommitteesIntegrationTest method phase0SlotCausesBadRequest.

@Test
void phase0SlotCausesBadRequest() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.PHASE0);
    spec = TestSpecFactory.createMinimalPhase0();
    DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
    final List<SyncCommitteeMessage> requestBody = List.of(new SyncCommitteeMessage(UInt64.ONE, dataStructureUtil.randomBytes32(), dataStructureUtil.randomUInt64(), new BLSSignature(dataStructureUtil.randomSignature())));
    Response response = post(PostSyncCommittees.ROUTE, jsonProvider.objectToJSON(requestBody));
    assertThat(response.code()).isEqualTo(SC_BAD_REQUEST);
    assertThat(response.body().string()).contains("Could not create sync committee signature at phase0 slot 1");
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) Response(okhttp3.Response) SyncCommitteeMessage(tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 9 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project teku by ConsenSys.

the class PostSyncCommitteesIntegrationTest method shouldGet200OkWhenThereAreNoErrors.

@Test
void shouldGet200OkWhenThereAreNoErrors() throws Exception {
    spec = TestSpecFactory.createMinimalAltair();
    DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final List<SyncCommitteeMessage> requestBody = List.of(new SyncCommitteeMessage(UInt64.ONE, dataStructureUtil.randomBytes32(), dataStructureUtil.randomUInt64(), new BLSSignature(dataStructureUtil.randomSignature())));
    final SafeFuture<List<SubmitDataError>> future = SafeFuture.completedFuture(Collections.emptyList());
    when(validatorApiChannel.sendSyncCommitteeMessages(any())).thenReturn(future);
    Response response = post(PostSyncCommittees.ROUTE, jsonProvider.objectToJSON(requestBody));
    assertThat(response.code()).isEqualTo(SC_OK);
    assertThat(response.body().string()).isEmpty();
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) Response(okhttp3.Response) List(java.util.List) SyncCommitteeMessage(tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 10 with BLSSignature

use of tech.pegasys.teku.api.schema.BLSSignature in project teku by ConsenSys.

the class PostSyncCommitteesIntegrationTest method shouldSubmitSyncCommitteesAndGetResponse.

@Test
void shouldSubmitSyncCommitteesAndGetResponse() throws IOException {
    spec = TestSpecFactory.createMinimalAltair();
    DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final List<SyncCommitteeMessage> requestBody = List.of(new SyncCommitteeMessage(UInt64.ONE, dataStructureUtil.randomBytes32(), dataStructureUtil.randomUInt64(), new BLSSignature(dataStructureUtil.randomSignature())));
    final SafeFuture<List<SubmitDataError>> future = SafeFuture.completedFuture(List.of(new SubmitDataError(UInt64.ZERO, errorString)));
    when(validatorApiChannel.sendSyncCommitteeMessages(requestBody.get(0).asInternalCommitteeSignature(spec).stream().collect(Collectors.toList()))).thenReturn(future);
    Response response = post(PostSyncCommittees.ROUTE, jsonProvider.objectToJSON(requestBody));
    assertThat(response.code()).isEqualTo(SC_BAD_REQUEST);
    final PostDataFailureResponse responseBody = jsonProvider.jsonToObject(response.body().string(), PostDataFailureResponse.class);
    assertThat(responseBody.failures.get(0).message).isEqualTo(errorString);
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) Response(okhttp3.Response) PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) List(java.util.List) SyncCommitteeMessage(tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Aggregations

BLSSignature (tech.pegasys.teku.api.schema.BLSSignature)12 Test (org.junit.jupiter.api.Test)10 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 MockResponse (okhttp3.mockwebserver.MockResponse)5 List (java.util.List)4 Response (okhttp3.Response)3 PostDataFailureResponse (tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse)3 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)3 SyncCommitteeMessage (tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage)3 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)3 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)3 GetNewBlockResponseV2 (tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2)2 SignedBeaconBlock (tech.pegasys.teku.api.schema.SignedBeaconBlock)2 SingleQueryParameterUtils.getParameterValueAsBLSSignature (tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils.getParameterValueAsBLSSignature)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Throwables (com.google.common.base.Throwables)1 Context (io.javalin.http.Context)1 Handler (io.javalin.http.Handler)1 HttpMethod (io.javalin.plugin.openapi.annotations.HttpMethod)1