Skip to content

Commit

Permalink
Merge pull request #295 from Concordium/identity-request
Browse files Browse the repository at this point in the history
Identity request
  • Loading branch information
orhoj authored Jan 18, 2024
2 parents c44c716 + 8ba8c15 commit b097582
Show file tree
Hide file tree
Showing 18 changed files with 323 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Purge remaining usages of V1 GRPC API.
- Added support for android through an AAR artifact.
- Added `ConcordiumHdWallet` class for deriving Concordium specific keys and randomness from a seed phrase.
- Added `Identity` class with method `createIdentityRequest` for creating identity requests.

## 6.0.0
- Added method `waitUntilFinalized` for waiting until a given transaction is finalized.
Expand Down
2 changes: 1 addition & 1 deletion concordium-base
Submodule concordium-base updated 42 files
+7 −0 haskell-src/Concordium/Types.hs
+56 −2 haskell-src/Concordium/Types/ProtocolVersion.hs
+16 −16 mobile_wallet/Cargo.lock
+2 −2 rust-src/Cargo.lock
+3 −0 rust-src/concordium_base/CHANGELOG.md
+15 −13 rust-src/concordium_base/benches/bulletproofs.rs
+61 −5 rust-src/concordium_base/benches/multiexp_bench.rs
+1 −2 rust-src/concordium_base/src/aggregate_sig/mod.rs
+1 −2 rust-src/concordium_base/src/bulletproofs/inner_product_proof.rs
+5 −7 rust-src/concordium_base/src/bulletproofs/range_proof.rs
+4 −6 rust-src/concordium_base/src/bulletproofs/set_membership_proof.rs
+4 −6 rust-src/concordium_base/src/bulletproofs/set_non_membership_proof.rs
+4 −2 rust-src/concordium_base/src/bulletproofs/utils.rs
+85 −19 rust-src/concordium_base/src/curve_arithmetic/bls12_381_instance.rs
+378 −0 rust-src/concordium_base/src/curve_arithmetic/ed25519_instance.rs
+245 −150 rust-src/concordium_base/src/curve_arithmetic/mod.rs
+1 −2 rust-src/concordium_base/src/curve_arithmetic/secret_value.rs
+1 −2 rust-src/concordium_base/src/dodis_yampolskiy_prf/secret.rs
+4 −7 rust-src/concordium_base/src/elgamal/mod.rs
+3 −4 rust-src/concordium_base/src/elgamal/secret.rs
+3 −3 rust-src/concordium_base/src/id/account_holder.rs
+1 −2 rust-src/concordium_base/src/id/id_verifier.rs
+1 −2 rust-src/concordium_base/src/id/identity_provider.rs
+5 −2 rust-src/concordium_base/src/id/secret_sharing.rs
+0 −1 rust-src/concordium_base/src/id/types.rs
+9 −10 rust-src/concordium_base/src/id/utils.rs
+0 −2 rust-src/concordium_base/src/pedersen_commitment/randomness.rs
+0 −2 rust-src/concordium_base/src/ps_sig/secret.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/aggregate_dlog.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_enc_eq.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_eq.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_eq_different_groups.rs
+0 −1 rust-src/concordium_base/src/sigma_protocols/com_eq_sig.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_ineq.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_lin.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/com_mult.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/dlog.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/dlogaggequal.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/enc_trans.rs
+1 −2 rust-src/concordium_base/src/sigma_protocols/vcom_eq.rs
+35 −149 rust-src/wallet_library/src/credential.rs
+43 −210 rust-src/wallet_library/src/identity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.concordium.sdk.crypto;

import com.concordium.sdk.crypto.wallet.IdentityRequestInput;
import com.concordium.sdk.crypto.wallet.Network;
import com.concordium.sdk.crypto.wallet.StringResult;
import com.concordium.sdk.exceptions.JNIError;
Expand Down Expand Up @@ -258,4 +259,13 @@ public static String getVerifiableCredentialBackupEncryptionKey(String seedAsHex
return getVerifiableCredentialBackupEncryptionKey(seedAsHex, network.getValue());
}
private static native String getVerifiableCredentialBackupEncryptionKey(String seedAsHex, String netAsStr);

/**
* Creates an identity request that is to be sent to an identity provider when
* creating a new identity.
* @param input {@link IdentityRequestInput} serialized as JSON
* @return JSON representing {@link StringResult}. If successful the field 'result' contains the identity request as JSON.
* If not successful, the 'err' field contains a {@link JNIError} detailing what went wrong.
*/
public static native String createIdentityRequestV1(String input);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.concordium.sdk.crypto.pointchevalsanders;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

Expand All @@ -15,7 +16,6 @@
*/
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode
@ToString
public class PSPublicKey {

/**
Expand All @@ -39,4 +39,10 @@ public static PSPublicKey from(final byte[] bytes) {
public byte[] getBytes() {
return Arrays.copyOf(bytes, bytes.length);
}

@Override
@JsonValue
public String toString() {
return Hex.encodeHexString(this.bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.concordium.sdk.crypto.CryptoJniNative;
import com.concordium.sdk.crypto.NativeResolver;
import com.concordium.sdk.crypto.bls.BLSSecretKey;
import com.concordium.sdk.crypto.ed25519.ED25519PublicKey;
import com.concordium.sdk.crypto.ed25519.ED25519SecretKey;
import com.concordium.sdk.exceptions.CryptoJniException;
Expand Down Expand Up @@ -169,28 +170,28 @@ public ED25519PublicKey getAccountPublicKey(int identityProviderIndex, int ident
* Derives id cred sec for a specific identity.
* @param identityProviderIndex the index of the identity provider interpreted as a u32.
* @param identityIndex the index of the identity interpreted as a u32.
* @return id cred sec encoded as a hex string
* @return id cred sec
*/
public String getIdCredSec(int identityProviderIndex, int identityIndex) {
public BLSSecretKey getIdCredSec(int identityProviderIndex, int identityIndex) {
String idCredSec = getStringResult((String seedAsHex, Network network) -> {
return CryptoJniNative.getIdCredSec(seedAsHex, network, identityProviderIndex, identityIndex);
});

return idCredSec;
return BLSSecretKey.from(idCredSec);
}

/**
* Derives the PRF key for a specific identity.
* @param identityProviderIndex the index of the identity provider interpreted as a u32.
* @param identityIndex the index of the identity interpreted as a u32.
* @return a PRF key encoded as a hex string
* @return a PRF key
*/
public String getPrfKey(int identityProviderIndex, int identityIndex) {
public BLSSecretKey getPrfKey(int identityProviderIndex, int identityIndex) {
String prfKey = getStringResult((String seedAsHex, Network network) -> {
return CryptoJniNative.getPrfKey(seedAsHex, network, identityProviderIndex, identityIndex);
});

return prfKey;
return BLSSecretKey.from(prfKey);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.concordium.sdk.crypto.wallet;

import com.concordium.sdk.crypto.CryptoJniNative;
import com.concordium.sdk.exceptions.CryptoJniException;
import com.concordium.sdk.serializing.JsonMapper;
import com.fasterxml.jackson.core.JsonProcessingException;

public class Identity {

/**
* Creates an identity request that is to be sent to an identity provider when
* creating a new identity.
* @param input the input required to generate an identity request
* @return an identity request serialized as JSON
*/
public static String createIdentityRequest(IdentityRequestInput input) {
StringResult result = null;
try {
String jsonStr = CryptoJniNative.createIdentityRequestV1(JsonMapper.INSTANCE.writeValueAsString(input));
result = JsonMapper.INSTANCE.readValue(jsonStr, StringResult.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}

if (!result.isSuccess()) {
throw CryptoJniException.from(result.getErr());
}

return result.getResult();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.concordium.sdk.crypto.wallet;

import java.util.Map;

import com.concordium.sdk.crypto.bls.BLSSecretKey;
import com.concordium.sdk.responses.blocksummary.updates.queues.AnonymityRevokerInfo;
import com.concordium.sdk.responses.blocksummary.updates.queues.IdentityProviderInfo;
import com.concordium.sdk.responses.cryptographicparameters.CryptographicParameters;

import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;

@Getter
@Builder
public class IdentityRequestInput {

@NonNull
private final CryptographicParameters globalContext;

@NonNull
private final Map<String, AnonymityRevokerInfo> arsInfos;

@NonNull
private final IdentityProviderInfo ipInfo;

private final long arThreshold;

@NonNull
private final BLSSecretKey idCredSec;

@NonNull
private final BLSSecretKey prfKey;

@NonNull
private final String blindingRandomness;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import com.concordium.grpc.v2.ArInfo;
import com.concordium.sdk.crypto.elgamal.ElgamalPublicKey;
import com.concordium.sdk.types.UInt32;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.*;
import lombok.extern.jackson.Jacksonized;

/**
* Anonymity revoker info
Expand All @@ -20,11 +23,14 @@ public final class AnonymityRevokerInfo {
/**
* A description of the anonymity revoker
*/
@JsonProperty("arDescription")
private final Description description;

@JsonProperty("arPublicKey")
private final ElgamalPublicKey anonymityRevokerPublicKey;
@Builder
public AnonymityRevokerInfo(int arIdentity, Description description, ElgamalPublicKey arPublicKey) {
@Jacksonized
public AnonymityRevokerInfo(int arIdentity, @JsonProperty("arDescription") Description description, ElgamalPublicKey arPublicKey) {
this.arIdentity = UInt32.from(arIdentity);
this.description = description;
this.anonymityRevokerPublicKey = arPublicKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.concordium.sdk.responses.blocksummary.updates.queues;

import lombok.*;
import lombok.extern.jackson.Jacksonized;

/**
* A description contains meta information about an {@link IdentityProviderInfo} or {@link AnonymityRevokerInfo}
* A description contains meta information about an {@link IdentityProviderInfo}
* or {@link AnonymityRevokerInfo}
*/
@ToString
@EqualsAndHashCode
@Getter
@Builder
@RequiredArgsConstructor
@Jacksonized
public class Description {
private final String name;
private final String url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import com.concordium.sdk.crypto.ed25519.ED25519PublicKey;
import com.concordium.sdk.crypto.pointchevalsanders.PSPublicKey;
import com.concordium.sdk.types.UInt32;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

/**
* Identity provider info
Expand All @@ -18,12 +21,15 @@
public final class IdentityProviderInfo {

private final UInt32 ipIdentity;
@JsonProperty("ipDescription")
private final Description description;
private final ED25519PublicKey ipCdiVerifyKey;
private final PSPublicKey ipVerifyKey;

@Builder
@Jacksonized
public IdentityProviderInfo(int ipIdentity,
@JsonProperty("ipDescription")
Description description,
ED25519PublicKey ipCdiVerifyKey,
PSPublicKey ipVerifyKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import com.concordium.sdk.crypto.pedersencommitment.PedersenCommitmentKey;
import lombok.Builder;
import lombok.Data;
import lombok.extern.jackson.Jacksonized;

/**
* A Set of Cryptographic parameters that are particular to the chain and
* shared by everybody who interacts with the chain.
*/
@Data
@Builder
@Jacksonized
public final class CryptographicParameters {

/**
Expand Down
30 changes: 30 additions & 0 deletions concordium-sdk/src/main/java/com/concordium/sdk/types/UInt32.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
import lombok.Getter;
import lombok.val;

import java.io.IOException;
import java.nio.ByteBuffer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

@EqualsAndHashCode
@Getter
@JsonSerialize(using = UInt32.UInt32Serializer.class)
public final class UInt32 {
public static final int BYTES = Integer.BYTES;
final int value;
Expand Down Expand Up @@ -50,4 +58,26 @@ public static UInt32 fromBytes(ByteBuffer source) {
public String toString() {
return String.valueOf(value);
}

/**
* A custom Jackson serializer is provided that makes the UInt32 JSON serialization
* compatible with the JSON format expected by the Rust libraries.
*/
static class UInt32Serializer extends StdSerializer<UInt32> {

public UInt32Serializer() {
this(null);
}

public UInt32Serializer(Class<UInt32> t) {
super(t);
}

@Override
public void serialize(
UInt32 uint, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeRawValue(Integer.toUnsignedString(uint.getValue()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testMainnetPublicAndSigningKeyMatch() throws UnsupportedEncodingExce
public void testMainnetIdCredSec() {
ConcordiumHdWallet wallet = ConcordiumHdWallet.fromHex(TEST_SEED, Network.MAINNET);

String idCredSec = wallet.getIdCredSec(2, 115);
String idCredSec = wallet.getIdCredSec(2, 115).toString();

assertEquals("33b9d19b2496f59ed853eb93b9d374482d2e03dd0a12e7807929d6ee54781bb1", idCredSec);
}
Expand All @@ -114,7 +114,7 @@ public void testMainnetIdCredSec() {
public void testMainnetPrfKey() {
ConcordiumHdWallet wallet = ConcordiumHdWallet.fromHex(TEST_SEED, Network.MAINNET);

String prfKey = wallet.getPrfKey(3, 35);
String prfKey = wallet.getPrfKey(3, 35).toString();

assertEquals("4409e2e4acffeae641456b5f7406ecf3e1e8bd3472e2df67a9f1e8574f211bc5", prfKey);
}
Expand Down
Loading

0 comments on commit b097582

Please sign in to comment.