Skip to content

Commit

Permalink
Moved teku deserializers from teku into web3signer (#1015)
Browse files Browse the repository at this point in the history
Web3signer is referencing a few deserializers / serializers from teku, and I'm removing them from teku, so I've recreated them in web3signer to reduce integration issues...
  • Loading branch information
rolfyone authored Aug 24, 2024
1 parent 3dafc7b commit 7160ffa
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
import tech.pegasys.teku.infrastructure.jackson.deserializers.uints.UInt64Deserializer;
import tech.pegasys.teku.infrastructure.jackson.deserializers.uints.UInt64Serializer;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector;
import tech.pegasys.teku.provider.BLSPubKeyDeserializer;
import tech.pegasys.teku.provider.BLSPubKeySerializer;
import tech.pegasys.teku.provider.BLSSignatureDeserializer;
import tech.pegasys.teku.provider.BLSSignatureSerializer;
import tech.pegasys.teku.provider.SszBitvectorSerializer;
import tech.pegasys.web3signer.common.JacksonSerializers.HexDeserialiser;
import tech.pegasys.web3signer.common.JacksonSerializers.HexSerialiser;
import tech.pegasys.web3signer.common.JacksonSerializers.StringUInt64Deserializer;
import tech.pegasys.web3signer.common.JacksonSerializers.StringUInt64Serialiser;
import tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest;
import tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.json.BlockRequestDeserializer;
import tech.pegasys.web3signer.core.service.http.serializers.BLSPubKeyDeserializer;
import tech.pegasys.web3signer.core.service.http.serializers.BLSPubKeySerializer;
import tech.pegasys.web3signer.core.service.http.serializers.BLSSignatureDeserializer;
import tech.pegasys.web3signer.core.service.http.serializers.BLSSignatureSerializer;
import tech.pegasys.web3signer.core.service.http.serializers.SszBitvectorSerializer;
import tech.pegasys.web3signer.signing.config.metadata.parser.SigningMetadataModule;
import tech.pegasys.web3signer.signing.config.metadata.parser.SigningMetadataModule.Bytes32Serializer;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.web3signer.core.service.http.serializers;

import tech.pegasys.teku.api.schema.BLSPubKey;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.apache.tuweni.bytes.Bytes;

public class BLSPubKeyDeserializer extends JsonDeserializer<BLSPubKey> {
public BLSPubKeyDeserializer() {}

@Override
public BLSPubKey deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return new BLSPubKey(Bytes.fromHexString(p.getValueAsString()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.web3signer.core.service.http.serializers;

import tech.pegasys.teku.api.schema.BLSPubKey;

import java.io.IOException;
import java.util.Locale;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class BLSPubKeySerializer extends JsonSerializer<BLSPubKey> {
public BLSPubKeySerializer() {}

@Override
public void serialize(BLSPubKey value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeString(value.toHexString().toLowerCase(Locale.ROOT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.web3signer.core.service.http.serializers;

import tech.pegasys.teku.api.schema.BLSSignature;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

public class BLSSignatureDeserializer extends JsonDeserializer<BLSSignature> {
public BLSSignatureDeserializer() {}

@Override
public BLSSignature deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return BLSSignature.fromHexString(p.getValueAsString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.web3signer.core.service.http.serializers;

import tech.pegasys.teku.api.schema.BLSSignature;

import java.io.IOException;
import java.util.Locale;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class BLSSignatureSerializer extends JsonSerializer<BLSSignature> {
public BLSSignatureSerializer() {}

@Override
public void serialize(BLSSignature value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeString(value.toHexString().toLowerCase(Locale.ROOT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.web3signer.core.service.http.serializers;

import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector;

import java.io.IOException;
import java.util.Locale;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class SszBitvectorSerializer extends JsonSerializer<SszBitvector> {
public SszBitvectorSerializer() {}

@Override
public void serialize(SszBitvector value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeString(value.sszSerialize().toHexString().toLowerCase(Locale.ROOT));
}
}

0 comments on commit 7160ffa

Please sign in to comment.