public byte[] createFor(Account account, Device device, boolean includeE164) throws InvalidKeyException {
    SenderCertificate.Certificate.Builder builder = SenderCertificate.Certificate.newBuilder()
        .setSenderDevice(Math.toIntExact(device.getId()))
        .setExpires(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(expiresDays))
        .setIdentityKey(ByteString.copyFrom(account.getIdentityKey(IdentityType.ACI).serialize()))
        .setSigner(serverCertificate)
        .setSenderUuid(account.getUuid().toString());

    if (includeE164) {
      builder.setSender(account.getNumber());
    }

    byte[] certificate = builder.build().toByteArray();
    byte[] signature;
    try {
      signature = Curve.calculateSignature(privateKey, certificate);
    } catch (org.signal.libsignal.protocol.InvalidKeyException e) {
      throw new InvalidKeyException(e);
    }

    return SenderCertificate.newBuilder()
                            .setCertificate(ByteString.copyFrom(certificate))
                            .setSignature(ByteString.copyFrom(signature))
                            .build()
                            .toByteArray();
  }
@Test
  void testCreateFor() throws IOException, InvalidKeyException, org.signal.libsignal.protocol.InvalidKeyException {
    final Account account = mock(Account.class);
    final Device device = mock(Device.class);
    final CertificateGenerator certificateGenerator = new CertificateGenerator(
        Base64.getDecoder().decode(SIGNING_CERTIFICATE),
        Curve.decodePrivatePoint(Base64.getDecoder().decode(SIGNING_KEY)), 1);

    when(account.getIdentityKey(IdentityType.ACI)).thenReturn(IDENTITY_KEY);
    when(account.getUuid()).thenReturn(UUID.randomUUID());
    when(account.getNumber()).thenReturn("+18005551234");
    when(device.getId()).thenReturn((byte) 4);

    assertTrue(certificateGenerator.createFor(account, device, true).length > 0);
    assertTrue(certificateGenerator.createFor(account, device, false).length > 0);
  }