Search in sources :

Example 1 with FilecoinAddress

use of tech.pegasys.web3signer.signing.filecoin.FilecoinAddress in project web3signer by ConsenSys.

the class FilecoinAddressTest method verifyAddress.

private void verifyAddress(final String address, final String payload, final FilecoinProtocol bls) {
    final FilecoinAddress filecoinAddress = FilecoinAddress.fromString(address);
    final String expectedPayload = payload.substring(2);
    assertThat(filecoinAddress.getPayload().toUnprefixedHexString()).isEqualTo(expectedPayload);
    assertThat(filecoinAddress.getProtocol()).isEqualTo(bls);
    String encodedAddress = filecoinAddress.encode(FilecoinNetwork.MAINNET);
    assertThat(encodedAddress).isEqualTo(address);
}
Also used : FilecoinAddress(tech.pegasys.web3signer.signing.filecoin.FilecoinAddress)

Example 2 with FilecoinAddress

use of tech.pegasys.web3signer.signing.filecoin.FilecoinAddress in project web3signer by ConsenSys.

the class FcJsonRpc method filecoinWalletVerify.

@JsonRpcMethod("Filecoin.WalletVerify")
public boolean filecoinWalletVerify(@JsonRpcParam("address") final String filecoinAddress, @JsonRpcParam("data") final Bytes dataToVerify, @JsonRpcParam("signature") final FilecoinSignature filecoinSignature) {
    final FilecoinAddress address = FilecoinAddress.fromString(filecoinAddress);
    final Bytes signature = Bytes.fromBase64String(filecoinSignature.getData());
    switch(address.getProtocol()) {
        case SECP256K1:
            checkArgument(filecoinSignature.getType() == SECP_VALUE, "Invalid signature type");
            return FilecoinVerify.verify(address, dataToVerify, SecpArtifactSignature.fromBytes(signature));
        case BLS:
            checkArgument(filecoinSignature.getType() == BLS_VALUE, "Invalid signature type");
            return FilecoinVerify.verify(address, dataToVerify, new BlsArtifactSignature(BLSSignature.fromBytesCompressed(signature)));
        default:
            throw new IllegalArgumentException("Invalid address protocol type");
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlsArtifactSignature(tech.pegasys.web3signer.signing.BlsArtifactSignature) FilecoinAddress(tech.pegasys.web3signer.signing.filecoin.FilecoinAddress) JsonRpcMethod(com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod)

Aggregations

FilecoinAddress (tech.pegasys.web3signer.signing.filecoin.FilecoinAddress)2 JsonRpcMethod (com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod)1 Bytes (org.apache.tuweni.bytes.Bytes)1 BlsArtifactSignature (tech.pegasys.web3signer.signing.BlsArtifactSignature)1